AppointmentDemo.java
import java.util.Scanner;
/**
Demonstration of the appointment classes
*/
public class AppointmentDemo
{
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);
}
}
}
}
Appointment.java
/**
A class to keep track of an 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;
}
}
Daily.java
public class Daily extends Appointment
{
public Daily (String description)
{
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
return true;
}
}
Onetime.java
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;
}
}
}
Monthly.java
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;
}
}
}
Solution
AppointmentDemo.java
import java.util.Scanner;
/**
Demonstration of the appointment classes
*/
public class AppointmentDemo
{
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);
}
}
}
}
Appointment.java
/**
A class to keep track of an appointment.
*/
public ab.
1. AppointmentDemo.java
import java.util.Scanner;
/**
Demonstration of the appointment classes
*/
public class AppointmentDemo
{
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);
}
}
}
}
Appointment.java
/**
A class to keep track of an appointment.
*/
public abstract class Appointment
{
private String description;
/**
2. 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;
}
}
Daily.java
public class Daily extends Appointment
{
public Daily (String description)
{
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
3. return true;
}
}
Onetime.java
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;
}
}
}
Monthly.java
public class Monthly extends Appointment
{
private int dayApp;
public Monthly (int dayAppInput, String description)
{
4. dayApp = dayAppInput;
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
if (day == dayApp)
{
return true;
}
else
{
return false;
}
}
}
Solution
AppointmentDemo.java
import java.util.Scanner;
/**
Demonstration of the appointment classes
*/
public class AppointmentDemo
{
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();
5. int day = in.nextInt();
for (Appointment a : appointments)
{
if (a.occursOn(year, month, day))
{
System.out.println(a);
}
}
}
}
Appointment.java
/**
A class to keep track of an 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);
/**
6. Converts appointment to string description.
*/
public String toString()
{
return description;
}
}
Daily.java
public class Daily extends Appointment
{
public Daily (String description)
{
setDescription(description);
}
public boolean occursOn(int year, int month, int day)
{
return true;
}
}
Onetime.java
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)
7. {
if ((year == yearApp) && (month == monthApp) && (day == dayApp))
{
return true;
}
else
{
return false;
}
}
}
Monthly.java
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;
}
}
}