GameBoard: 2026 FRQ 4
A step-by-step solution to the 2026 AP CSA FRQ 4 (GameBoard), covering summing a row of a 2D array of objects and detecting whether every value in it shares one property in Java.
Scoring a single row of a colorful game board — with a bonus for an all-one-color row — is the challenge in this AP Computer Science A free-response question, and like this year's Array/ArrayList question, it asks for just a single method rather than the usual two-part split.
What This FRQ Tests
- AP CSA units: Unit 8 (2D Array) and Unit 4 (Iteration)
- Core skill: looping across one row of a 2D array of objects to both accumulate a total and check a shared property
- Secondary skill: tracking a running "has everything matched so far" flag across a loop, similar to checking whether a whole row shares one value
- Official category: "2D Array" — this year's version asks for a single method rather than the usual two-part structure, but it's still always FRQ 4 on the AP CSA exam
The Setup
- The given
Spaceclass (not modified) provides:String getColor()— the space's colorint getPoints()— the space's point value
GameBoardholds:private Space[][] board
- You're asked to write one method:
int getPointsForRow(int targetRow)— sums the points in a row, doubling the total if every space in that row shares the same color
Writing getPointsForRow(int targetRow)
The Rule, Broken Down
- Add up the point value of every space in row
targetRow. - Separately, check whether every space in that row has the same color.
- If they're all the same color, the row's point value is double the sum.
- Otherwise, the row's point value is just the sum, unchanged.
Step-by-Step Approach
- Remember the color of the row's very first space — that's what every other space will be compared against.
- Start a running point total at
0, and a flag tracking "still all one color" starting attrue. - Loop across every column of
targetRow. - At each space, add its points to the running total.
- Also compare its color to the first space's color — if it ever differs, flip the flag to
false. - After the loop, return either double the total or the plain total, depending on the flag.
The Code
public int getPointsForRow(int targetRow)
{
int sum = 0;
boolean sameColor = true;
String firstColor = board[targetRow][0].getColor();
for (int c = 0; c < board[targetRow].length; c++)
{
sum = sum + board[targetRow][c].getPoints();
if (!board[targetRow][c].getColor().equals(firstColor))
{
sameColor = false;
}
}
if (sameColor)
{
return sum * 2;
}
else
{
return sum;
}
}
Why Each Piece Matters
-
firstColoris read once, before the loop, from column0oftargetRow— every other space's color gets compared against this fixed reference point, not against whatever the previous space happened to be. -
sameColorstartstrueand can only flip tofalse— this is the standard pattern for "check that nothing in this sequence violates a rule." If the loop never finds a mismatch (including the case of a single-column row, where the loop body runs only once and trivially matches itself), the flag correctly staystrue. -
The sum accumulates on every iteration, regardless of color — summing and color-checking are two independent jobs happening in the same pass over the row, not two separate loops.
-
.equals()for comparing colors, never==—getColor()returns aString, and identical-looking color names aren't guaranteed to be the same object in memory.
Tracing the Example
Using the question's own 4×5 board:
- Row 0: colors
"orange","red","blue","green","red"— not all the same (the very second space already breaks the match) →sameColorendsfalse. Points:100 + 100 + 500 + 500 + 100 = 1300. Since not all one color, the row's value is the plain sum: 1300 — matches the question's expectedgetPointsForRow(0). - Row 2: colors
"red","red","red","red","red"— every space matchesfirstColor, sosameColorstaystruefor the whole loop. Points:200 + 300 + 100 + 200 + 200 = 1000. Since all one color, the row's value is doubled:1000 * 2 =2000 — matches the question's expectedgetPointsForRow(2)exactly.
Common Mistakes to Avoid
-
Comparing each space's color to the previous space's color instead of a single fixed
firstColor. This can incorrectly report "all the same" for a row like red, red, blue, blue (each space matches its immediate neighbor, but the row as a whole has two different colors). -
Computing the sum and the color check in two separate loops instead of one combined pass — not incorrect, just unnecessary extra work when both can be done together.
-
Comparing colors with
==instead of.equals(). TwoStringobjects with identical text aren't guaranteed to be the same object in memory. -
Doubling the sum unconditionally, or forgetting to double it at all — double check that the multiplication only happens inside the
sameColorbranch.
Key Takeaways
- "Does every element share some property with the first one" is the same running-flag pattern as "is this sequence in increasing order" — start
true, flip tofalsethe moment a mismatch is found, never flip back. - Two independent computations over the same data (here, a running sum and a running color check) can usually share one loop instead of needing two separate passes.
- Not every 2D array FRQ splits into two parts — some, like this one, ask for a single method that combines a couple of smaller ideas (summing, and checking a shared property) into one pass.
Need help preparing for the AP exam?
FRQs are one of the toughest parts of the AP CS exam. I offer 1-on-1 tutoring to help you work through practice problems, tighten up your responses, and build the confidence to earn full credit on exam day.
Book a tutoring session →