2013 AP CSA FRQ 2: TokenPass - Solution

2013 AP CSA FRQ 2: TokenPass

Topic: Arrays & Circular Movement

Skills: Circular array traversal, random distribution, game simulation

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

Points: 9 | Time: ~22 minutes

Part (a)

Write the constructor that initializes the game board.

Try First! Attempt before viewing solution.

Solution

public TokenPass(int numPlayers)
{
    board = new int[numPlayers];
    for (int i = 0; i < board.length; i++)
    {
        board[i] = (int)(Math.random() * 10) + 1;
    }
    currentPlayer = (int)(Math.random() * numPlayers);
}

Part (b)

Write the distributeCurrentPlayerTokens method.

Solution

public void distributeCurrentPlayerTokens()
{
    int tokens = board[currentPlayer];
    board[currentPlayer] = 0;
    int pos = currentPlayer;
    
    for (int i = 0; i < tokens; i++)
    {
        pos = (pos + 1) % board.length;
        board[pos]++;
    }
}

Key Concepts

✓ Math.random() * n gives [0, n)
✓ Add 1 to shift range to [1, n]
✓ Use modulo for circular array wrap
✓ Clear current position before distributing

Common Mistakes

Wrong random number range
Forgetting to zero out current position
Not wrapping with modulo
Distributing to current position

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]