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

Java help.. Here is what I have so far, I would like help on my subclasses, impl

ID: 3578280 • Letter: J

Question

Java help..

Here is what I have so far, I would like help on my subclasses, implementing super class and getting user date by year, month and day.

Implementing a superclass Appointment and subclass Onetime, Daily and Monthly. An appointment has a description (for example, "see dentist") and a date. 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 fill an array of Appointment objects with a mixture of appointments. Have the user enter a date and print out all appointments that occure on that date.

---Appointment---

public abstract class Appointment
{
private String description;

//Constructs an appointment without a description.
public Appointment()
{
description = "";
}

//Sets the description of this appointment.
public void setDescription(String description)
{
this.description = description;
}

//Determines if this appointment occurs on the given date.
public abstract boolean occursOn(int year, int month, int day);

//Converts appointment to string description.
public String toString()
{
return description;
}
}

----AppointmentMain----

public class AppointmentMain
{
public static void main(String[] args)
{
Appointment[] appointments = new Appointment[4];
appointments[0] = new Daily("Brush your teeth.");
appointments[1] = new Monthly(1, "Visit grandma.");
appointments[2] = new OneTime(2015, 11, 1, "Dentist appointment.");
appointments[3] = new OneTime(2015, 10, 31, "Trick or Treat.");

Scanner in = new Scanner(System.in);
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
for (Appointment a : appointments)
{
if (a.occursOn(year, month, day))
{
System.out.println(a);
}
}
}
}

---Daily--

public class Daily extends Appointment
{
public Daily (String description)
{
setDescription(description);
}

public boolean occursOn(int year, int month, int day)
{
return true;
}
}

--Monthly--

public class Monthly extends Appointment
{
private int dayApp;

public Monthly (int dayAppInput, String description)
{
dayApp = dayAppInput;
setDescription(description);
}

public boolean occursOn(int year, int month, int day)
{
if (day == dayApp)
{
return true;
}
else
{
return false;
}

}
}

---OneTime----

public class OneTime extends Appointment
{
private int monthApp;
private int yearApp;
private int dayApp;

public OneTime(int yearAppInput, int monthAppInput, int dayAppInput, String description)
{
yearApp = yearAppInput;
monthApp = monthAppInput;
dayApp = dayAppInput;
setDescription(description);
}

public boolean occursOn(int year, int month, int day)
{
if ((year == yearApp) && (month == monthApp) && (day == dayApp))
{
return true;
}
else
{
return false;
}
  
}
}

Explanation / Answer

The code is fine as per given requirements but it would be better if you provide the getters and setters methods for all the new attributes in each of the subclasses.

Even there should be a getter method for the "description" attribute in the superclass Appointment.

There should be setters for the subclasses so that if there is a requirement to update the appointment details by customers it should be possible.

Getters are required to display the appointments that belong to each customer/user.

It is suggested to ask the user for input using println statements to get year, month and day inputs

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