MasterOrder free response answer

The MasterOrder problem from the 2010 AP Computer Science Exam is typical of free response problems that test Lists. The problem requires you to manipulate a List and the objects inside.

Review the MasterOrder free response problem with AP CS Tutor Brandon Horn.

MasterOrder Part (a): getTotalBoxes

public int getTotalBoxes()
 {
  int boxes = 0;

  for (CookieOrder order : orders)
   boxes += order.getNumBoxes();

  return boxes;
 }

MasterOrder Part (b): removeVariety

public int removeVariety(String cookieVar)
 {
  int boxesRemoved = 0;

  for (int i = orders.size() - 1; i >= 0; i--)
  {
   if (cookieVar.equals(orders.get(i).getVariety()))
    boxesRemoved += orders.remove(i).getNumBoxes();
  }

  return boxesRemoved;
 }

Get AP CS Help

2010 AP CS Exam Free Response Solutions

Recommended Practice Problems

Leave a Reply