Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A. Implement a superclass called Appointment and subclasses OneTime, Daily, Week

ID: 3534592 • Letter: A

Question

A. Implement a superclass called Appointment and subclasses OneTime, Daily, Weekly, and Monthly. An Appointment has a description (for example, “Meet with interviewer about jobâ€) and a date and time. Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then, in a TestAppointment class, fill an array of Appointment objects with a mixture of different kinds of appointments. Ask a user to enter a date and print out all appointments that occur on that date.

B. Improve your Appointment program by giving the user the option to add new Appointments. The user must specify the type of the appointment, the description, and the date and time.

C. Improve the program further by letting the user save the appointment data to a file and reload the data from a file. The saving part is straightforward: make a method saveApptData. In it, save the type, description, date, and time 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 loadApptData method to load the data.

As always, the source code must be indented properly and contain comments that describe important parts of the algorithm.

Explanation / Answer

Please rate with 5 stars :)


Here is what you need:


public class Appointment2
{
private Date date;
private Time time;
private String location;
private String appointed;
private String purpose;
public Appointment2(Date date, Time time, String location, String appointed, String purpose)
{
this.date = date;
this.time = time;
this.location = location;
this.appointed = appointed;
this.purpose = purpose;
}

public Appointment2()
{
this.date = date;
this.time = time;
this.location = location;
this.appointed = appointed;
this.purpose = purpose;
}
public Date getDate()
{
return date;
}
public static void main (String[]args) throws Exception
{
Date date1 = new Date(2004, 11, 22);
Time time1 = new Time(12, 3, 23);
Appointment2 aAppt = new Appointment2(date1, time1, "Suite 201", "Crenshaw", "Checkup");
System.out.println(aAppt.getDate());

}
}[CODE]

[CODE]
public class Date
{
protected int year;
protected int month;
protected int day;
public Date(int year, int month, int day) throws Exception
{
if (year < 0 || year > 8089)
throw new Exception("***Year must be > 0 and < 8089");
if (month > 12 || month < 1)
throw new Exception("***Month must be less than 12 and greater than 0");
if (day < 1 || day > 31)
throw new Exception("***Day must be greater than 1 and less than 31");
if (month == 9 && day > 30 || month == 4 && day > 30 || month == 11 && day > 30 )
throw new Exception("***( Months 4, 9. and 11 only has 30 days");
if (year % 4 != 0 && month == 2 && day > 28 )
throw new Exception("***( Month 2 has 28 days");
if (year % 4 == 0 && month == 2 && day > 29)
throw new Exception("***You cannot have more than 29 days in 2");
this.year = year;
this.month = month;
this.day = day;
}
public Date()
{
this.year = year;
this.month = month;
this.day = day;
}
static Date getDate(int year, int month, int day)
{
if (year < 0 || year > 8089)
return null;
if (month > 12 || month < 1)
return null;
if (day < 1 || day > 31)
return null;
try
{
return new Date(year, month, day);
}
catch(Exception e)
{
//convincing compiler we are handling exception
}

return null;
}

public int getYear()
{
return year;
}

public int getMonth()
{
return month;
}
public int getDay()
{
return day;
}

public void setDate(int year, int month, int day) throws Exception
{
if (year < 0 || year > 8089)
throw new Exception("***Year must be > 0 and < 8089");
if (month > 12 || month < 1)
throw new Exception("***Month must be less than 12 and greater than 0");
if (day < 1 || day > 31)
throw new Exception("***Day must be greater than 1 and less than 31");
if (month == 9 && day > 30 || month == 4 && day > 30 || month == 11 && day > 30 )
throw new Exception("***( Months 4, 9. and 11 only has 30 days");
if (year % 4 != 0 && month == 2 && day > 28 )
throw new Exception("***( Month 2 has 28 days");
if (year % 4 == 0 && month == 2 && day > 29)
throw new Exception("***You cannot have more than 29 days in 2");
return;
}

public String toString()
{
return "The date is: year:" + year + " month:" + month + " day:" + day;
}

public boolean equals( Date otherDate )
{
return getYear() == (otherDate.getYear())&&
getDay() == (otherDate.getDay()) &&
getMonth() == (otherDate.getMonth());
}
public int compareTo ( Date otherDate )
{
if (getYear() != (otherDate.getYear()))
return getYear() - (otherDate.getYear());
else if (getMonth() != (otherDate.getMonth()))
return getMonth() - (otherDate.getMonth());
else
return getDay() - (otherDate.getDay());
}
public Date tomorrow()
{
getDay();
if (month == 9 && day == 30 || month == 4 && day == 30 || month == 11 && day == 30 ) {
day = 1;
month++;
} else if (year % 4 != 0 && month == 2 && day == 28 ) {
day = 1;
month = 2;
} else if (year % 4 == 0 && month == 2 && day == 29) {
day = 1;
month = 3;
} else {
day++;
}
return null;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote