Help with assignment please
Hello i need help with an assignment i have to do. using five classes, i have to create a planner that uses an array and can store an "activity" for a specific date and time. here's two classes done already:
The three other classes are as follows (and what they need to contain):
date: OurDate - the day/month/year of the event
time: OurTime - the hour/minute that event starts at
description: String - a description of event
getDate () : OurDate - returns date of event
getTime() : OurTime - returns time of event
getDescription () : String - returns description of event
setDate (OurDate) - sets date to parameter value
setTime (OurTime) - sets time to parameter value
setDescription (String) - sets description to parameter value
toString() : String - displays event to a String
inputFromKeyboard () - prompts input from keyboard for all
activities : Event - array of Event
numEvents : int - how many events are stored in the activities
inputActivity () - adds an Event to the activities array if there
is room and if there is no other activity for that date and time
displayOneDay(OurDate) - looks through array and displays
all events for the parameter date
displaySevenDays (OurDate) - displays events for the seven
days starting at parameter date
deleteEvent (OurDate, OurTime) - looks through array for an
event at parameter date and time, and deletes it (if found)
and finally Assignment class, which only has method main and loops everything. note i cant use any librarys and stuff because we havent done anything with them yet.
i cant figure this out for the life of my. what goes in the setDate getDate setTime getTime fields? how do i tell teh array to check if a date and time is already entered?
help is greatly, greatly appreciated.
The get* methods don't accept any parameters. They simply return the result of the datatype specified. So the getDate would return a type OurDate which will be what is stored within the property date (which I don't like the property name of, but that's not my call). Setters are reverse, so the set* methods accept the datatype provided within the brackets and return void. Those would set the associated property.
Since you are just using an array, you simply iterate it and check each item until you reach the end. To check them, you simply iterate the activities and compare each existing activity. You can simply check each field, or if you are far enough to do it, implement the Comparator interface and write the compareTo. A hint to do that with just comparisons of each property:
Also, the array will potentially give you problems. Since you cannot resize the array by simply appending to it, you'll need to keep track of the size or use try/catch exceptions to see if it goes out of bounds (currently you do have a variable for the size of the array, which I assume is the existing items currently, and can be compared to the length). Copying an array is a simple matter of constructing a new array that is larger, than iterating each item to add to it, then assigning that back to the member. Or you can use the Arrays class which has a copyOf method that should do the trick if you need to resize. If you weren't stuck on Event datatype in the instructions, I'd actually suggest a priority queue based on the Date and Time provided. Add an event, and it automatically inserts it based on date and time, so when you iterate the list it would be sequential in order of date and time.
You'll need to look over the date handling as well. Its not quite as cut and dry as you have here; if you change the month, the number of days will change which may alter the currently assigned day. Same goes with the year if it were february 29 for example.
Thank you very much for the hep Fou-Lu. I was able to get my program fully working. The only small problem I have left is when I delete an event, the most recent activity is deleted rather than what i specified. This is the code I am using:
You're comparing the last event to the first event for if it should be set to null. The signature you have is also incorrect, as the original post indicates this takes the date and time.
It's simpler than this, even without the use of Arrays or collections:
|All times are GMT +1. The time now is 11:38 AM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.