2004 AP CSA FRQ 4: Robot
Topic: Arrays & Simulation
Skills Tested: Array traversal, state management, simulation logic, boundary checking
Curriculum Alignment: Unit 2 (Selection/Iteration) (2025-2026 AP CSA)
Points: 9 | Time Estimate: ~22 minutes
Part (a)
Write the forwardMoveBlocked method that returns true if the robot cannot move in the direction it's facing.
Solution
private boolean forwardMoveBlocked()
{
if (facingRight)
return pos == hall.length - 1;
else
return pos == 0;
}
Part (b)
Write the move method that decrements the current position's value and moves the robot according to specified rules.
Solution
private void move()
{
if (hall[pos] > 0)
hall[pos]--;
if (hall[pos] == 0)
{
if (forwardMoveBlocked())
facingRight = !facingRight;
else if (facingRight)
pos++;
else
pos--;
}
}
Part (c)
Write the clearHall method that repeatedly moves the robot until the hall is clear, returning the number of moves.
Solution
public int clearHall()
{
int count = 0;
while (!hallIsClear())
{
move();
count++;
}
return count;
}
Key Concepts
Common Mistakes to Avoid
Scoring Guidelines
Total Points: 9
Points are awarded for:
- Correct loop structure and bounds
- Proper method calls and return statements
- Correct conditional logic
- Handling edge cases appropriately
Partial credit is available for demonstrating understanding even with minor syntax errors.
Official College Board Resources
Continue Studying
About the Author: Tanner Crow is a certified AP Computer Science teacher with 11+ years of experience helping students succeed on the AP CSA exam.
Last updated: January 2026