2010 AP CSA FRQ 1: MasterOrder
Topic: ArrayList & Order Processing
Skills: ArrayList traversal, accumulator pattern, order fulfillment logic
Unit: Unit 4 (Data Collections) (2025-2026 AP CSA)
Points: 9 | Time: ~22 minutes
Part (a)
Write the getTotalBoxes method that returns the total number of boxes ordered.
Solution
public int getTotalBoxes()
{
int boxes = 0;
for (CookieOrder order : orders)
{
boxes += order.getNumBoxes();
}
return boxes;
}Part (b)
Write the removeVariety method that removes all orders of a specific variety and returns the total boxes removed.
Solution
public int removeVariety(String cookieVar)
{
int removed = 0;
int i = 0;
while (i < orders.size())
{
if (orders.get(i).getVariety().equals(cookieVar))
{
removed += orders.get(i).getNumBoxes();
orders.remove(i);
}
else
{
i++;
}
}
return removed;
}Key Concepts
Common Mistakes
Official Resources
Author: Tanner Crow - AP CS Teacher, 11+ years