NOTE: Use the class names and method signatures exactly as given in the following descriptions. We'll be running your code with our own main program that will rely on the given names and signatures.
Appointment
, and three subclasses (OneTimeOnly
, Daily
,
Monthly
). It's OK to create a monthly appointment that occurs on the 29th, 30th, or 31st of the month
(we'll
just assume that if a month doesn't have the given number of days, then there is no appointment that month). The date/time field for
an Appointment should be of type GregorianCalendar
. This is a type available in the java.util library. Look at the
Java API to learn how to use GregorianCalendar. Here are a couple of hints to get you started:
public GregorianCalendar (int year, int month, int dayOfMonth, int hourOfDay, int minute)
For this program, you may assume that all appointments are for the current year (2015). Because we'll be assuming that times for appointments always begin on the hour and that the duration of an appointment is one hour, the value for the minute parameter should always be 0.
get()
method.
Here's an
example of how to extract the month:
GregorianCalendar date = new GregorianCalendar(2015, 3, 16, 8, 0); int month = date.get(GregorianCalendar.MONTH); // value of month will be 3
AppointmentBook
class should maintain a private field of type ArrayList<Appointment>.
occursOn (int year, int month, int day)
that checks whether this appointment occurs
on the given date. For example, if momVisit
is a Monthly appointment that occurs at 2pm on the 14th of each
month, then
momVisit.occursOn(2015, 3, 16)
returns false, and momVisit.occursOn(2015, 9, 14)
returns true.
makeAppointment(Appointment app)
in the AppointmentBook class that attempts to add
the given appointment to the appointment book. The program should not add an appointment
if the new appointment will conflict with any appointment already in the appointment book.
If there is no conflict, the given appointment is added to the appointment book. If there
is a conflict, the method should return without adding the
given appointment to the appointment book. Later in the course we'll see how to use
Exceptions to provide a better way to handle conflicts.
In developing this method, you should not check the type of any appointment (in other
words, your program should not use Java's instanceof
operator or
getClass()
method). Rely on dynamic dispatch instead to force an object to behave appropriately for
its type.
This method is a little tricky. As a first pass at the method, don't check for conflicts - just make sure the program can add an appointment to the appointment book. Get the rest of the program working. Then go back and try writing the code that checks for conflicts.
listAll()
in the AppointmentBook class that displays information about all appointments
currently in the appointment book. You'll need to provide an appropriate toString()
method for each of your appointment subclasses. The output of the listAll()
method should look similar to this:
dentist (one-time appointment): March 2, 2015 at 3pm CS 220X (daily appointment) at 8am Visit Mom (monthly appointment) Every month on the ** 16 ** day of the month at 12pm Go to dump (monthly appointment) Every month on the ** 3 ** day of the month at 11am doctor (one-time appointment): January 16, 2015 at 11am
Export your Eclipse project to a zip file and submit the zip file via web-based turnin. To export a project, go to File | Export… and choose Archive File from the General folder. Check off the entire project in the top left window and make sure the format is .zip and not .tar. Finally, give the archive file a name and click finish.
The name of the turnin project is Homework 3.
Programs submitted after 5pm on April 7 will be tagged as late, and will be subject to the late homework policy.