package calendarExample; /** * * @author Fawzi Emad * @version 11/6/2006 * * Implements a class of Day objects. Each Day stores its name, day of month, * and a list of appointments. * */ public class Day { private String[] appointments; private String dayName; // e.g. "Saturday" private int date; // e.g. 23 /** * Constructor * @param dayName Name of day * @param date Day of month for day */ public Day(String dayName, int date) { this.dayName = dayName; this.date = date; appointments = new String[0]; } /** * Adds an appointment to the day. * @param a Description of appointment. */ public void addAppointment(String a) { // Create a bigger array and add new string as last element. String[] bigger = new String[appointments.length + 1]; for (int i = 0; i < appointments.length; i++) bigger[i] = appointments[i]; bigger[bigger.length - 1] = a; appointments = bigger; } /** * Creates a string from a day object. */ public String toString() { if (dayName.equals("Unused")) return "Unused"; String s = dayName + "\t" + (date < 10?" ":"") // Add extra space in front of single-digit dates + date + " Appointments: "; for (int i = 0; i < appointments.length; i++) s += " " + (i + 1) + ". " + appointments[i]; return s; } }