Users browsing this thread: 1 Guest(s)
Java help: not really sure where I want to go with this
#1
Okay, so

I need to learn some object-oriented programming. Namely, I need to figure out how to work with inheritance and super/subclasses.

As of right now, I'm tasked with making an Appointment program that uses this whole idea that classes can break into one superclass and a ton of other subclasses. This particular task involves making the Appointment class the superclass and then making "One-time", "Daily", "Weekly", and "Monthly" subclasses to Appointment.
A method will then accept a date input and matches it up with a database of inserted appointments, printing out all the appointments that would occur on the input date.
On top of this, all of the dates I need to store for the program must be put into an array of Appointment objects.

I can most definitely code a program that can take inputs and print out all the stored events that would happen on a particular day. However, I can't seem to wrap my head around doing this with a superclass and subclasses.

Does anyone have any good suggestions as to what I should do for this? As in, what exactly is getting inherited from the Appointment superclass, and where am I able to store the array of Appointment objects?
HAVE I BEEN MISLEAD?? [Image: TeamStory.gif] THE DREAM ISN'T DEAD???

Thanked by:
#2
This doesn't sound like the ideal example for teaching OOP. The suggested subclasses are probably not what you'd make if it were an actual application (you would, for example, have just one Appointment that has some Pattern indicating how many times that appointment is going to occur. Then also possibly some 'dummy' appointments that are saved in the calendar by day, week and/or month, such that you don't have to go through the full list of appointments to get all appointments for a given day/week/month).


But, even given the somewhat shabby example, there's still some 'OOP to apply'.
First, you may want to consider how you want to solve the problem;
Given a date, list all Appointments that occur on that date.

An/the OO-way would be to ask each of the Appointments if they occur on that date, and print something if that is the case (you could even let the appointments print that, but then the method would be useless for any other purpose you may think of later). Thus, the Appointment superclass should have a method that checks if it occurs on a given date. Each of the subclasses should implement that method.

When you start implementing the subclasses, you may notice there's some data they all have (or should have) in common; a (start) date. (if the recurring appointments also go infinitely far back in time, any date will do)
Any time every subclass of a class has the same data, you may want to think about moving that data to the superclass. Sometimes, especially when the project is only just starting, it may be warranted to keep the data in the subclasses. However whenever you know that the data will be part of every subclass, it's a rare case when the data should not go to the parent class.


Regarding the array of appointments, I'd say you would put them wherever your program enters. However another possibility would be to store the array as a static field in the Appointment class.
On one hand this means it's (relatively) nice and orderly, however it also means that you cannot have multiple sets of appointments at the same time.
Thanked by: Koopaul, Rosencrantz
#3
Hello, I'm new to this place, I am new to this site but am anxious to join in, Woohoo. Nice to meet you all

Logo Polo Shirts
Work Polo Shirts
Sport Polo Shirts
Thanked by: Rosencrantz
#4
btw figured I'd say that the issue's been long resolved so just lock this already~


EDIT:: WAITWAIT NVM I need this thread

I'm going to need to learn Selenium to fix up a website issue for a job related to what I've been asking. Needless to say, do any of you mods mind if I use this thread to make some generated bot messages to make sure I get the program nailed down? I don't mean advertisements or anything, I just wanted to see if I can get some successful input AND output with the program, through my own profile.
HAVE I BEEN MISLEAD?? [Image: TeamStory.gif] THE DREAM ISN'T DEAD???

Thanked by:
#5
As long as the spambot functions through your account, and the posts are nowhere but this thread, I don't mind.
Specs 'n' Headphones has been revamped! Check it, yo.
[Image: 10y3mgj.png][Image: groove-1.gif]
Thanks to Pik and Solink; they are sexy people. Heart
Thanked by: Rosencrantz
#6
I have an app idea for you if you haven't already settled on one, though it requires a lot of AI work and it's a long read:

It's a bot that surfs the internet posts messages on forums/facebook, HOWEVER it is not a spambot. It is a oB2Ko Mariobot.

It reads the page's source and parses posts to "read" what people are posting. It puts the strings through some sort of test to find out what the topic is about and what people are saying (somewhat similar to some spambots with the kinda-slightly-vaguely on-topic ads) then makes its own post based on what you would say.

Already hard-coded into the program is a sort of "posting personality", a way of making the Facebook posts or forum posts look like you actually wrote it. A sort of grammar guidelines it has to follow. You would also need a XML file or DB that it reads from to find your interests, like your favorite game or food or vacation spot. It could have several "emotions", where it chooses one based on what keywords were found in the last few posts.

Here's an example:
- Mighty posts that she loves Chinese food.
- [Example Member] posts that they hate Teriyaki Sauce.
- The bot reads the first post
- The bot reads the string "I love Chinese food"
-- The poster is Mighty Jetters, so the "I" is converted to "Mighty Jetters"
-- The bot checks for the verb after the subject "I", which is "love", which the bot associates with a certain positive factor
-- The bot checks for the object after the verb "love", which is "Chinese food". The bot recognizes that the Subject has a positive feeling about the Object
-- The bot reads oB2KoMario.XML and finds out that he has a positive feeling about Chinese food, but not as high.
- The bot reads the second post
- The bot reads the string "I hate Teriyaki Sauce"
-- The poster is [Example Member], so the "I" is converted to "[Example Member]"
-- The bot checks for the verb after the subject "I", which is "hate", which the bot associates with a certain negative factor
-- The bot checks for the object after the verb "hate", which is "Teriyaki Sauce". The bot recognizes that the Subject has a negative feeling about a different Object
-- The bot reads oB2KoMario.XML and finds out that he has a positive feeling about Teriyaki Sauce
- The bot compares the two posts and using Google or something figures out that Teriyaki Sauce is related to Chinese food
- The bot creates a string for the response
-- The bot knows that post 1 is positive and post 2 is negative. The bot is positive about the same thing as post 1 and thus agrees with post 1.
-- The bot starts the string with "Actually, I agree with Might Jetters on this. I like Chinese food". The "actually" comes from identifying the alternate point of view after Mighty Jetters' post
-- The bot is positive about the thing post 2 is negative about and thus disagrees with post 2.
-- The bot adds "and I love Teriyaki Sauce" because it knows there are two objects being talked about.
- The bot posts the string on tSR


obviously it's harder than that but i was just throwing that out there!

My original idea with this was to let the app run in my old age and have it continue posting on forums and FB after I die, heh
#7
OKAY SO SELENIUM TESTING!!

Right now, I'm going to see if Selenium will complete a post for me. Don't mind me~
OKAY SO SELENIUM TESTING!!

If this works, then this means that I've got something working.
Hey, it worked!

Hey guys, I'm posting using an external program! This kicks ass Smile
Now, let's see if the program still works from another site.
Aaaaaaaaand it did, excellent!
And now we're back to the original test thread.
HAVE I BEEN MISLEAD?? [Image: TeamStory.gif] THE DREAM ISN'T DEAD???

Thanked by:
#8
Now, this is being run from Eclipse. Let's see where this goes.
AAAAAAAAAAHAHAHAHAHA

SUP LOSERS, I'M NOT EVEN USING A BROWSER RIGHT NOW
Posting exclusively using a java program. I can bulk-post if I wanted to.

Cool
Well okay I lied; Selenium has to pull up Firefox in order to make these posts.

BUTTTTTTTTTbutt I'm telling it to do it via Java so ~heh~
man my posts are shitty today
HAVE I BEEN MISLEAD?? [Image: TeamStory.gif] THE DREAM ISN'T DEAD???

Thanked by:
#9
Now transform your bot into a post-thanking bot which thanks all posts and give it to Mighty
Cute
Thanked by: Alex
#10
(07-20-2011, 01:10 PM)Previous Wrote: Now transform your bot into a post-thanking bot which thanks all posts and give it to Mighty
Cute

I can actually legitimately do this



she'll need Selenium though !!
HAVE I BEEN MISLEAD?? [Image: TeamStory.gif] THE DREAM ISN'T DEAD???

Thanked by:
#11
In the meantime, here's a post from a GUI that I made.
one more time
HAVE I BEEN MISLEAD?? [Image: TeamStory.gif] THE DREAM ISN'T DEAD???

Thanked by:


Forum Jump: