Other 2012 FR Questions FR other years Be Prepared Home
A-1
Part (a)
  public void addClimb(String peakName, int climbTime)
  {
    climbList.add(new ClimbInfo(peakName, climbTime));
  }

Part (b)
  public void addClimb(String peakName, int climbTime)
  {
    int i = 0;
    while (i < climbList.size() && climbList.get(i).getName().compareTo(peakName) <= 0) 1
      i++; 2
    climbList.add(i, new ClimbInfo(peakName, climbTime));
  }
Notes:
  1. Compare i and climbList.size() first to avoid IndexOutOfBoundsException.
  2. Or, a bit more verbose, using break (which is not in the AP subset but OK):
        ...
        while (i < climbList.size())
        {
          if (climbList.get(i).getName().compareTo(peakName) <= 0)
            break;
          i++;
        }
    

Part (c)

NO YES

Other 2012 FR Questions | Back to Contents

Copyright © 2012 by Skylight Publishing
support@skylit.com