2004 AP CSA FRQ 4: Robot - Complete Solution

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.

Try It First! Attempt to solve this part before viewing the solution. Use the concepts: Array traversal.

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

Boolean instance variables track robot state
Boundary checking prevents array index errors
Simulation problems require careful state updates
Use helper methods (hallIsClear) even if not implementing them

Common Mistakes to Avoid

Off-by-one errors when checking array bounds
Forgetting to toggle direction with facingRight = !facingRight
Not decrementing hall[pos] before checking if it's zero
Infinite loops if move() doesn't update state correctly

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

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

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]