2011 AP CSA FRQ 3: FuelDepot - Solution

2011 AP CSA FRQ 3: FuelDepot

Topic: Interfaces & Finding Minimum

Skills: Interface method calls, find minimum algorithm, robot movement

Unit: Unit 4 (Data Collections) (2025-2026 AP CSA)

Points: 9 | Time: ~22 minutes

Study Guide: Unit 3: Class Creation

Part (a)

Write the nextTankToFill method that returns the index of the tank with lowest fuel.

Try First! Attempt before viewing solution.

Solution

public int nextTankToFill(int threshold)
{
    int tankWithLeast = 0;
    for (int i = 1; i < tanks.size(); i++)
    {
        if (tanks.get(i).getFuelLevel() < tanks.get(tankWithLeast).getFuelLevel())
        {
            tankWithLeast = i;
        }
    }
    
    if (tanks.get(tankWithLeast).getFuelLevel() <= threshold)
    {
        return tankWithLeast;
    }
    else
    {
        return filler.getCurrentIndex();
    }
}

Part (b)

Write the moveToLocation method that moves the robot to a specific tank index.

Solution

public void moveToLocation(int tankIndex)
{
    int currentIndex = filler.getCurrentIndex();
    
    if (tankIndex > currentIndex)
    {
        filler.changeDirection(FuelRobot.FORWARD);
        filler.moveForward(tankIndex - currentIndex);
    }
    else if (tankIndex < currentIndex)
    {
        filler.changeDirection(FuelRobot.BACKWARD);
        filler.moveForward(currentIndex - tankIndex);
    }
}

Key Concepts

✓ Standard find-minimum algorithm tracking index
✓ Start loop at 1 when comparing to index 0
✓ Threshold check after finding minimum
✓ Movement requires direction change first

Common Mistakes

Returning tank object instead of index
Forgetting threshold check
Wrong direction constants
Negative movement distance
Practice Similar: 2019 FRQ 2 | 2022 FRQ 2 | 2023 FRQ 2

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]