please comment the code so that i am able to follow what is done i know this is
ID: 3534575 • Letter: P
Question
please comment the code so that i am able to follow what is done i know this is lengthy so any help is beneficial because i have no idea where to start
program will prompt the user for one of three menu choices:
Create a new appointment.
Print a Range of appointments.
Print all the appointments.
Quit (Ends the program).
Each appointment will store certain values
? The date of the appointment, as a month, day, and year
? The description of the appointment, “Taking my sweetie to a programming class.â€
? The type of appointment, (One?Time, Daily, Monthly)
Create an “Appointment†class, to store the date and description.
Create three sub?classes that inherit from Appointment. These will represent the Once, Daily,
and Monthly appointment types. They will each store their appointment type as an
occurenceflag variable, an int.
Create an appropriate Interface so that you can reference all three sub?class types
using a for loop in your executable. For example, since you need to print the details of each stored appointment, an interface will allow you to call the same method for all three sub?class types, as we discussed in class.
Take Note: This means that each of your sub?classes will both extend Appointment and implement from your interface (whatever you call it). You will have to modify the beginning of each class, as we saw in lecture, to account for this.
You will implement the occursOn() method in the Appointment class. When the user chooses “1†from the menu, the program will take the date they enter, and will check it all of the stored Appointments. If an appointment exists on the same month/day/year as the one the user is trying to enter, the system should NOT allow the new appointment to be created.
(This is not real?world, but our company’s employees are busy people: 1 appointment per day!)
Keep the Appointment and the sub?classes as simple and as parsimonious as possible (see next item).
The Executable file should handle ALL of the
User input
Parsing of the entered date (User types it in as a string, “05/26/2013â€, and a separate method INSIDE your executables file will return back an int[] with the dates parsed. (Remember how we put methods outside of main() in our executables in lecture?)
The looping of the program (The user chooses option 1, they enter the Appt. information, it adds the new appointment to the ArrayList<>, then it goes back to the menu choices, allows the user to choose “2†or “3†or “quitâ€)
DO NOT try to use the Date, SimpleDate, DateFormat, or GregorianCalendar, or any other built? in date?related classes in the Java Library to handle the dates. You need to parse the user string, and “turn the string into an int in java†(Hint: Google likes that little phrase!)?In other words, when you enter mm/dd/yyyy, the mm, dd, and yyyy all get turned into int values stored inside an int[] array.
What it should look like:
Welcome to Appointment App!
I?I? §I?======================================
1?41?4 §I?Make Choice ("1": New, "2": Print Range, "3": Print All, "quit"):1 I?I? §I?
1?41?4Â §I?Enter New Appointment Date in mm/dd/yyyy format: 1/1/2013
I?I? §I?
1?41?4Â §I?Enter New Appointment Description: Beginning of the Year!
I?I? §I?
1?41?4Â §I?Enter Type (1 = Once, 2 = Daily, 3 = Monthly):1
I?I? §I?New One-Time Appointment Added for 1/1/2013 I?I? §I?======================================
1?41?4 §I?Make Choice ("1": New, "2": Print Range, "3": Print All, "quit"):1 I?I? §I?
1?41?4Â §I?Enter New Appointment Date in mm/dd/yyyy format: 12/31/2013
I?I? §I?
1?41?4Â §I?Enter New Appointment Description: End of the year!
I?I? §I?
1?41?4Â §I?Enter Type (1 = Once, 2 = Daily, 3 = Monthly):1
I?I? §I?New One-Time Appointment Added for 12/31/2013 I?I? §I?======================================
1?41?4 §I?Make Choice ("1": New, "2": Print Range, "3": Print All, "quit"):1 I?I? §I?
1?41?4Â §I?Enter New Appointment Date in mm/dd/yyyy format: 5/1/2013
I?I? §I?
1?41?4Â §I?Enter New Appointment Description: The Beginning of May!
I?I? §I?
1?41?4Â §I?Enter Type (1 = Once, 2 = Daily, 3 = Monthly):1
I?I? §I?New One-Time Appointment Added for 5/1/2013 I?I? §I?======================================
1?41?4 §I?Make Choice ("1": New, "2": Print Range, "3": Print All, "quit"):1 I?I? §I?
1?41?4Â §I?Enter New Appointment Date in mm/dd/yyyy format: 8/14/2013
I?I? §I?
1?41?4 §I?Enter New Appointment Description: Beginning of Fall Semester! I?I? §I?
1?41?4Â §I?Enter Type (1 = Once, 2 = Daily, 3 = Monthly):1
I?I? §I?New One-Time Appointment Added for 8/14/2013 I?I? §I?======================================
1?41?4 §I?Make Choice ("1": New, "2": Print Range, "3": Print All, "quit"):2 I?I? §I?
1?41?4Â §I?Enter START Date in mm/dd/yyyy format: 2/1/2013
I?I? §I?
1?41?4Â §I?Enter END Date in mm/dd/yyyy format: 11/31/2013
I?I? §I?5/1/2013 : "The Beginning of May!", One-Time
I?I? §I?8/14/2013 : "Beginning of Fall Semester!", One-Time I?I? §I?======================================
1?41?4 §I?Make Choice ("1": New, "2": Print Range, "3": Print All, "quit"):3 I?I? §I?1/1/2013 : "Beginning of the Year!", One-Time
I?I? §I?12/31/2013 : "End of the year!", One-Time
I?I? §I?5/1/2013 : "The Beginning of May!", One-Time
I?I? §I?8/14/2013 : "Beginning of Fall Semester!", One-Time I?I? §I?======================================
1?41?4Â §I?Make Choice ("1": New, "2": Print Range, "3": Print All, "quit"):quit
Explanation / Answer
import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; @SuppressWarnings("serial") public class Appointment implements Comparable, Serializable { private String id; private String title; private String description; private Date start; private Date end; private String location; private String createdBy; private List attendees = new ArrayList(); private boolean allDay = false; private AppointmentStyle style = AppointmentStyle.DEFAULT; private String customStyle; private boolean readOnly = false; public Appointment() { } /** * Returns the unique identifier for thisAppointment. * The field is optional (and not used by gwt-cal) and therefore * may be null. * * @return A unique identifier for this Appointment (optional). */ public String getId() { return id; } /** * Sets the unique identifier of this Appointment. * This identifier is optional. * * @param id */ public void setId(String id) { this.id = id; } /** * Returns the configured start time-stamp of this Appointment. * * @return A date object with the date and time this appointment starts on */ public Date getStart() { return start; } /** * Sets the start time-stamp of this Appointment. * * @param start * A date object with the date and time this appointment starts */ public void setStart(Date start) { this.start = start; } /** * Returns the configured end time-stamp of this Appointment. * * @return A date object with the date and time this appointment ends on */ public Date getEnd() { return end; } /** * Sets the end time-stamp of this Appointment. * * @param end * A date object with the date and time this appointment starts */ public void setEnd(Date end) { this.end = end; } /** * Returns the identifying title of this Appointment. * * @return The title's short text */ public String getTitle() { return title; } /** * Sets the identifying title of this Appointment. * * @param title * The title's short text */ public void setTitle(String title) { this.title = title; } /** * Returns a description for this Appointment. * * @return The appointment's description */ public String getDescription() { return description; } /** * Sets the description of this Appointment. * * @param description * The title's short text */ public void setDescription(String description) { this.description = description; } /** * Returns a location of this Appointment. * * @return The appointment location. */ public String getLocation() { return location; } /** * Sets the location of this Appointment. * * @param location * The appointment location */ public void setLocation(String location) { this.location = location; } /** * Returns a creator of this Appointment. * * @return The appointment creator description. */ public String getCreatedBy() { return createdBy; } /** * Sets the creator of this Appointment. * * @param createdBy * The appointment creator description. */ public void setCreatedBy(String createdBy) { this.createdBy = createdBy; } /** * Returns the collection of associated attendees. * * @return The currently configured list of attendees */ public List getAttendees() { return attendees; } /** * Sets the attendees associated to this Appointment. * * @param attendees * The entities associated (attending) this * Appointment */ public void setAttendees(List attendees) { this.attendees = attendees; } /** * Compares this Appointment with the specified * appointment based first on the start dates of * each appointment and then (if they happen to be the same), on the * end dates. * * @param appointment * The appointment to compare this one to * @return a negative integer if this appointment * is before appointment, zero if * both appointments have the same start/ * end dates, and a positive integer if * this appointment is after * appointment. */ public int compareTo(Appointment appointment) { int compare = this.getStart().compareTo(appointment.getStart()); if (compare == 0) { compare = appointment.getEnd().compareTo(this.getEnd()); } return compare; } /** * Tells whether this Appointment spans more than a single day, * based on its start and end properties. * * @return true if the start and end * dates fall on different dates, false otherwise. */ public boolean isMultiDay() { if (getEnd() != null && getStart() != null) { return !DateUtils.areOnTheSameDay(getEnd(), getStart()); } throw new IllegalStateException( "Calculating isMultiDay with no start/end dates set"); } /** * Returns the configured value of the allDay property, which * indicates if this Appointment should be considered as * spanning all day. It is left to the view rendering this * Appointment to decide how to render an appointment based on * this property value. For instance, the month view, will display the * Appointment at the top of the days in a week. * * @return The current value of the allDay property */ public boolean isAllDay() { return allDay; } /** * Configures the the allDay property, which indicates if this * Appointment should be considered as spanning all day. It is * left to the view rendering this Appointment to decide how to * render an appointment based on this property value. For instance, the * month view, will display the Appointment at the top of the * days in a week. * * @param allDay * The current value of the allDay property */ public void setAllDay(boolean allDay) { this.allDay = allDay; } public Appointment clone() { Appointment clone = new Appointment(); clone.setId(this.id); clone.setAllDay(this.allDay); clone.setAttendees(this.attendees); clone.setCreatedBy(this.createdBy); clone.setDescription(this.description); clone.setEnd(DateUtils.newDate(this.end)); clone.setLocation(this.location); clone.setStart(DateUtils.newDate(this.start)); clone.setTitle(this.title); clone.setStyle(this.style); clone.setCustomStyle(this.customStyle); return clone; } public AppointmentStyle getStyle() { return style; } public void setStyle(AppointmentStyle style) { this.style = style; } public String getCustomStyle() { return customStyle; } public void setCustomStyle(String customStyle) { this.customStyle = customStyle; } public boolean isReadOnly() { return readOnly; } public void setReadOnly(boolean readOnly) { this.readOnly = readOnly; } } Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.