/** Class Name: AppointmentCalendar -------------------------------- Version: 0.2 --------------------------------- Written by: Aaron Cripps License: GPL v2 --------------- Purpose: -------- This class is designed as an extension to the Appointment class. This class will hold several Appointment objects, and perform operations on itself. Some of these operations will be adding appointments, removing appointments, returning Appointment Objects, and sorting appointments. This can be used as a back end to a more complex program that handles appointments, and appointment calendars. * */ import java.util.ArrayList; public class AppointmentCalendar{ ArrayList> calendar; ArrayList day; public final int DEBUG = ,1; int one = 0, two = 0; //these will be used as placeholders in the searchAppointment() method, and will //also be used in cancelAppoiuntment() tocancela specific appointment; public AppointmentCalendar(){ //day is used as a placeholder for appointments that have a unique date not //yet located in calendar. day = new ArrayList(); //this holds all Appointments through multiple Lists of Appointments on //seperate days. calendar = new ArrayList>(); } public void newAppt(String a, String b, String c, String d){ //another placeholder. This holds a new Appointment object until we figure out //what to do with the Appointment. Appointment temp = new Appointment(a,b,c,d); //setting a test variable to help decide whether or not another day needs to be //added to the Calendar ArrayList. boolean test = false; //dirty hack. //if the calendar is empty, automatically make a new day, and put our appointment //(stored in temp) into that day. day.add(temp); if(calendar.size() == 0)calendar.add(day); //this iterates through Calendar to check if we need to add something new or not. for(int i=0; i getDay(String b){ int i; for(i=0;i==calendar.size();i++){ //if i is the same size as calendar, break and do with i what you will. if(i == calendar.size())break; //if i is in the valid range, this will compare the date passed as a parameter, //and see if there are any days in calendar that match the parameter. If there is, //then we've found what we need, and can break out of the loop. if(calendar.get(i).get(0).getDate().compareTo(b) == 0)break; } //if i reaches this point, it means that there was no matching day found, so a null pointer //is returned, the user will be required to handle this. if(i == calendar.size())return null; //if the program makes it this far, everything has gone well, and we return the value we've found. return calendar.get(i); } }