//------------------------------------------------------------------------- /** * This class represents a rudimentary timetable that contains a set * of appointments. Appointments are organized by hour of the day and * day of the week. * * @author Stephen Edwards * @version Feb 22, 2013 */ public class TimeTable { //~ Instance/static variables ............................................. private Appointment[][] appointments; //~ Constructor ........................................................... // ---------------------------------------------------------- /** * Creates a new TimeTable object. */ public TimeTable() { appointments = new Appointment[7][24]; } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Add another appointment. If there is already an existing appointment * scheduled for the given day/time, it will be replaced. * @param day the day of the week on which this appointment * falls (0-6) * @param appointment the appointment to add */ public void addAppointment(int day, Appointment appointment) { appointments[day][appointment.hour()] = appointment; } // ---------------------------------------------------------- /** * Look up the appointment scheduled for a given day and hour. * @param day the day of the week to look up (0-6) * @param hour the hour of the day to look up (0-23) * @return the appointment scheduled for the given time, or null * if there is none */ public Appointment appointmentFor(int day, int hour) { return appointments[day][hour]; } }