ACSA Exam Prep
← All free-response questions
Question 3 · Data Analysis with ArrayList · 5 points

Food Truck Orders

A food truck keeps its orders in an ArrayList of Order objects.

public class Order
{
    /** Returns the name of the item ordered */
    public String getItem()
    { /* implementation not shown */ }

    /** Returns the number of that item ordered */
    public int getQuantity()
    { /* implementation not shown */ }

    // There may be instance variables, constructors,
    // and methods that are not shown.
}

public class FoodTruck
{
    /** The orders, in the order they were placed; never null */
    private ArrayList<Order> orders;

    /** Removes every order for item whose quantity is less than
     *  minQty and returns the total quantity of the removed
     *  orders. The remaining orders stay in their original order.
     */
    public int cancelSmall(String item, int minQty)
    { /* to be implemented */ }

    // There may be instance variables, constructors,
    // and methods that are not shown.
}

Your class

5 points

Write cancelSmall. Suppose orders contains (item, quantity):

[(taco, 2), (burrito, 1), (taco, 5), (taco, 1), (nachos, 3)]

After cancelSmall("taco", 3) returns 3, orders is [(burrito, 1), (taco, 5), (nachos, 3)].

Tab inserts spaces. Drafts save as you type.
Self-score
0 / 5