For P12.9 Be sure to define at least the following classes: 1) Appointment: stor
ID: 3701980 • Letter: F
Question
For P12.9 Be sure to define at least the following classes: 1) Appointment: stores information for a single appointment. 2) AppointmentCalendar: stores a list of appointments for a user. 3) AppointmentTime: stores time information for an appointment 4) AppointmentDate: stores date information for an appointment. 5) AppointmentMenu: manages a menu for a user. 6) ApointmentSystem: starts the AppointmentMenu application. Write a java program to design an appointment calender. An appointment includes the date, starting time, nding time, and a description; for example, Dentist 2012/10/1 17:30 18:30 CSl class 2012/10/2 08:30 10:00 Supply a user interFace to add appointment, remove canceled appointments, and print out ular day. Follow the design process that was described in this chapter. Your solution should include a class Appointment Calender that is not coupled with the Scanner or PrintStream Classes.Explanation / Answer
//----------- Appointment.java-----------
public class Appointment {
private int appointmentId;
private String description;
private AppointmentDate date;
private AppointmentTime startTime;
private AppointmentTime endTime;
public Appointment(String description, AppointmentDate date, AppointmentTime startTime, AppointmentTime endTime) {
this.description = description;
this.date = date;
this.startTime = startTime;
this.endTime = endTime;
this.appointmentId = AppointmentIdGenerator.getNextId();
}
public int getAppointmentId() {
return appointmentId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public AppointmentDate getDate() {
return date;
}
public void setDate(AppointmentDate date) {
this.date = date;
}
public AppointmentTime getStartTime() {
return startTime;
}
public void setStartTime(AppointmentTime startTime) {
this.startTime = startTime;
}
public AppointmentTime getEndTime() {
return endTime;
}
public void setEndTime(AppointmentTime endTime) {
this.endTime = endTime;
}
@Override
public String toString() {
return "Appointment [appointmentId=" + appointmentId + ", description=" + description + ", date=" + date
+ ", startTime=" + startTime + ", endTime=" + endTime + "]";
}
}
//-------------- AppointmentCalendar.java------------------------
public class AppointmentCalendar {
private List<Appointment> appointments;
public boolean addAppointment(Appointment appointment) {
appointments.add(appointment);
return false;
}
public List<Appointment> getAppointments() {
return appointments;
}
public List<Appointment> getAppointmentsForDay(Date day) {
List<Appointment> appointmentsForDay = new ArrayList<>();
for(Appointment appointment : appointments) {
if(isDateEqual(appointment.getDate().getDate(), day)) {
appointmentsForDay.add(appointment);
}
}
return appointmentsForDay;
}
private boolean isSlotAvailable(Appointment appointment) {
// TODO : Provide slot checking logic
return true;
}
private boolean isDateEqual(Date first, Date second) {
return false;
}
}
//-------------------- AppointmentTime.java
public class AppointmentTime {
private Date time;
}
// ------------- AppointmentDate.java
public class AppointmentDate {
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
//------------ AppointmentMenu.java ----------------
public class AppointmentMenu {
public void addAppointment(AppointmentCalendar calendar, Appointment appointment) {
}
public void removeAppointment() {
}
public void printAppointments() {
}
}
// --------------- AppointmentSystem.java ----------------
public class AppointmentSystem {
public static void main(String[] args) {
System.out.println("===== Welcome to Appointment System =====");
int opt = 0;
Scanner scanner = new Scanner(System.in);
do {
System.out.println("1. Add an appointment.");
System.out.println("2. Cancel an appointment.");
System.out.println("3. Exit.");
opt = Integer.valueOf(scanner.nextLine());
switch(opt) {
case 1: System.out.println("Ener appointment details");
System.out.print("Description:");
scanner.nextLine();
System.out.print("Date:");
scanner.nextLine();
System.out.print("Start Time:");
scanner.nextLine();
System.out.print("End Time:");
scanner.nextLine();
break;
case 2: System.out.println("Ener appointment ID to cancel");
break;
case 3:
scanner.close();
System.exit(1);
default: System.out.println("Choose proper option.");
}
} while (opt !=3);
scanner.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.