2010 AP CSA FRQ 1: MasterOrder - Solution

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.

Try First! Attempt before viewing solution.

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

✓ Enhanced for loop for simple accumulation
✓ While loop when removing from ArrayList
✓ Only increment index when NOT removing
✓ Use equals() for String comparison

Common Mistakes

Using for-each loop when removing elements
Incrementing index after removal (skips elements)
Using == instead of equals() for Strings
Not accumulating removed boxes
Practice Similar: 2019 FRQ 3 | 2021 FRQ 3 | 2023 FRQ 3

Official Resources

Author: Tanner Crow - AP CS Teacher, 11+ years

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]