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
Part (a)
Write the nextTankToFill method that returns the index of the tank with lowest fuel.
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
Common Mistakes
Official Resources
Author: Tanner Crow - AP CS Teacher, 11+ years