ClimbingClub free response answer

The ClimbingClub problem from the 2012 AP Computer Science Exam is typical of free response problems that test lists.

Review the ClimbingClub free response solution with AP CS Tutor Brandon Horn.

ClimbingClub Part (a): addClimb in order run

  public void addClimb(String peakName, int climbTime)
  {
    climbList.add(new ClimbInfo(peakName, climbTime));
  }

ClimbingClub Part (b): addClimb in alphabetical order

  public void addClimb(String peakName, int climbTime)
  {
    int i = 0;
    
    while(i < climbList.size() &&
         peakName.compareTo(climbList.get(i).getName()) > 0)
      i++;
    
   climbList.add(i, new ClimbInfo(peakName, climbTime));
  }

ClimbingClub Part (c): distinctPeakNames

(i) – No
(ii) – Yes

The implementation checks adjacent elements to identify distinct peak names. This will only work if the list is sorted.

Get AP CS Help

2012 AP CS Exam Free Response Solutions