I am a new software engineering student and I am having serious trouble with this assignment. This is a JAVA class.
"Part 1 (45 points) Create an AppointmentBook class that stores a collection of Appointments. Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a date. A Onetime appointment occurs only once, Daily occurs every day, and Monthly occurs once a month. Write a method occursOn(int year, int month, int day) that checks (returns) whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches with the specified day, that is, checking that monthly appointment, X, occurs on the 15 th day of the month. Subsequently, in a tester, fill an AppointmentBook’s collection of Appointment objects with a mixture of appointments. Have the user then enter a date and print out all appointments that occur on that date.
Part 2 (25 points) Improve the appointment book class. Make a method that allows adding new appointments. The method parameters must include the type of the appointment, the description, and the date.
Part 3 (30 points) Improve the appointment book program by having a method that saves the appointment data to a file and a separate method to reload the data from a file. The saving part is straightforward: Make a method save. Save the type, description, and date to a file. The loading part is not so easy. First determine the type of the appointment to be loaded, create an object of that type, and then call a load method to load the data.
Bonus (10 points) Create a Graphical User Interface (GUI) for your appointment book that displays appointments, allows appointment creation, and loading and saving files. If you need help or review on GUIs, read Chapter 10 in the text book. Points here will be given based on how many features and how well laid out your GUI is. It is bonus because you will likely have to read ahead and learn some skills on your own. So, do not feel pressured to do it, but it will help you with future material to come. "
I am all done with part 1. Here is my code.
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Appointment {
private String description;
private Date date;
public Appointment(String description, int year, int month, int day) throws ParseException {
this.description = description;
DateFormat dateFormatter = new SimpleDateFormat(String.format("yyyy-MM-dd"));
this.date = dateFormatter.parse(String.format("%d-%d-%d", year, month, day));
}
public boolean occursOn(int year, int month, int day) throws ParseException {
DateFormat dateFormatter = new SimpleDateFormat(String.format("yyyy-MM-dd"));
Date checkedDate = dateFormatter.parse(String.format("%d-%d-%d", year, month, day));
return checkedDate.equals(this.date);
}
public void print() {
System.out.println(String.format("Appointment: %s\nDate: %s", this.description, this.date.toString()));
}
public Date getDate() {
return this.date;
}
}
I am having trouble with the other parts!! Can anyone please help me? Thanks!
Aucun commentaire:
Enregistrer un commentaire