Other 2006 FR Questions FR other years Be Prepared Home
A-1
Part (a)
  // 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 (((Appointment)apptList.get(i)).conflictsWith(appt))
      apptList.remove(i);
    else
      i++; 1
  }
Notes:
  1. if two appointments in a row must be removed,
        for (i = 0; i < apptList.size(); i++)
          if (((Appointment)apptList.get(i)).conflictsWith(appt))
            apptList.remove(i);
    will miss the second one.

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 (int i = 0; i < apptList.size(); i++)
      if (((Appointment)apptList.get(i)).conflictsWith(appt))
        return false;

    apptList.add(appt);
    return true;
  }

Other 2006 FR Questions | Back to Contents

Copyright © 2006 by Skylight Publishing
support@skylit.com