Implement a superclass Appointment and subclasses Onetime, Daily and monthly. An
ID: 3759869 • Letter: I
Question
Implement a superclass Appointment and subclasses Onetime, Daily and monthly. An appointment has a description (for example "see dentist") and a date. Write a mthod occurOn (int year, in month, int day) that checks whether the appointment occurs on that date. For example, for monthly appointment, you must check wether the day of the month matches. Then fill an aray of Appointment objectives with a micture of appointments. Have the user eneter a date and print out of all appointments that occur on that date.
I been trying to figrue this out for about two hours now and get a lot of errors codes and dont know where to begin or just start over. I honestly do now know where to begin.
Explanation / Answer
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 Date: %s", this.description, this.date.toString())); } public Date getDate() { return this.date; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.