| Other 2006 FR Questions | FR other years | Be Prepared Home |
// returns true if the time interval of this Appointment
// overlaps with the time interval of other;
// otherwise, returns false
public boolean conflictsWith(Appointment other)
{
return getTime().overlapsWith(other.getTime());
}
Part (b) // removes all appointments that overlap the given Appointment
// postcondition: all appointments that have a time conflict with
// appt have been removed from this DailySchedule
public void clearConflicts(Appointment appt)
{
int i = 0;
while (i < apptList.size())
if (apptList.get(i).conflictsWith(appt))
apptList.remove(i);
else
i++; 1
}
Notes:
Part (c) // if emergency is true, clears any overlapping appointments and adds
// appt to this DailySchedule; otherwise, if there are no conflicting
// appointments, adds appt to this DailySchedule;
// returns true if the appointment was added;
// otherwise, returns false
public boolean addAppt(Appointment appt, boolean emergency)
{
if (emergency)
{
clearConflicts(appt);
apptList.add(appt);
return true;
}
for (Appointment ap : apptList)
if (ap.conflictsWith(appt))
return false;
apptList.add(appt);
return true;
}
|
Copyright © 2006 by Skylight Publishing
support@skylit.com