Ap Csa 2019 Frq 4 Lightboard

FRQ Archive2019 FRQs › FRQ 4: LightBoard
2019 AP CSA • 2D Array

AP CSA 2019 FRQ 4: LightBoard

Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF

9 Points Medium-Hard Unit 4
Question Type 2D Array
Skills Tested 2D boolean array initialization, Math.random() probability, column count, three-rule conditional
Difficulty Medium-Hard
Recommended Time 22 minutes

What This Problem Asks

2019 AP CSA FRQ 4 LightBoard asks students to write a constructor and an evaluation method for a 2D boolean light display. The constructor initializes every light with a 40% probability of being on using Math.random(). evaluateLight counts on-lights in a column and applies three rules: ON+even-count→false; OFF+div-by-3-count→true; otherwise return current status.

What This FRQ Tests

This FRQ tests Unit 4: 2D Arrays and Unit 2 (Math.random(), modulo, multi-condition if-else chain).

Official Question & PDF

Download Full FRQ PDF →

PDF cannot display on this device. Open PDF directly →

Timer 22:00

Provided Code

public class LightBoard
{
    private boolean[][] lights;
    /** Initializes lights: each light has 40% probability of being on.
     *  Precondition: numRows > 0, numCols > 0 */
        public LightBoard(int numRows, int numCols) {
        /* part (a) */
    }
    /** Evaluates light at row, col using 3 rules.
     *  Precondition: row and col are valid indexes */
        public boolean evaluateLight(int row, int col) {
        /* part (b) */
    }
}

Part A — 4 Points

Write the LightBoard constructor: initialize lights as a numRows × numCols boolean array where each light has a 40% probability of being set to true (on).

Write Your Solution

Drag corner to expand ▽

Scoring Rubric (Part A — 4 points)

+1 Traverses all rows and columns with no bounds errors
+1 Uses Math.random() to generate a random value
+1 Assigns random boolean (40% probability of true)
+1 Correctly initializes lights as a 2D boolean array of the correct dimensions

Solution

public LightBoard(int numRows, int numCols)
{
    lights = new boolean[numRows][numCols];
    for (int r = 0; r < numRows; r++)
    {
        for (int c = 0; c < numCols; c++)
        {
            lights[r][c] = Math.random() < 0.4;
        }
    }
}

Part B — 5 Points

Write evaluateLight: count on-lights in column col (including the current light), then apply three rules to determine return value.

Write Your Solution

Drag corner to expand ▽

Scoring Rubric (Part B — 5 points)

+1 Accesses lights[row][col] to check current status
+1 Counts the number of on-lights in column col
+1 Rule 1: light is ON and count in column is even → return false
+1 Rule 2: light is OFF and count in column is divisible by 3 → return true
+1 Rule 3: return current status (algorithm)

Solution

public boolean evaluateLight(int row, int col)
{
    int onCount = 0;
    for (int r = 0; r < lights.length; r++)
    {
        if (lights[r][col])
        {
            onCount++;
        }
    }
    if (lights[row][col] && onCount % 2 == 0)
    {
        return false;
    }
    if (!lights[row][col] && onCount % 3 == 0)
    {
        return true;
    }
    return lights[row][col];
}
Count includes the current light: The rules say "number of lights in its column that are on, including the current light." So count ALL lights in column col that are on.

Common Mistakes to Avoid

Forgetting to initialize lights = new boolean[numRows][numCols]

The constructor must explicitly create the 2D array before assigning elements. Without the initialization line, lights is null and the loop causes NullPointerException.

Applying rules in wrong order

The three rules are checked in order: Rule 1 (on + even), Rule 2 (off + div by 3), Rule 3 (return current status). Rules 1 and 2 are mutually exclusive since a light can't be both on and off, but the order still matters for clarity.

Exam Tips

Math.random() < 0.4 gives 40% probability of true. This is the standard pattern for probability initialization on AP CSA.
evaluateLight must count on-lights in the entire column col, not just row col. Traverse all rows for the same column index.

Scoring Summary

Part Method Points
Part A Write 4
Part B Write 5
Total 9

Want the Complete 2019 FRQ Solutions?

Browse all past AP CSA FRQs with full solutions and scoring breakdowns.

FRQ Archive →

Related FRQs

2D Array 2022 FRQ 4: Data — Random fill with constraints and column increasing check 2D Array 2023 FRQ 4: BoxOfCandy — 2D array column operations and specified traversal

Study the Concepts

Unit 4 Study Guide →

Struggling with FRQs? Get 1-on-1 Help

Work directly with Tanner — AP CS teacher with 11+ years experience and 1,845+ verified tutoring hours. 54.5% of students score 5s (vs. 25.5% national average).

5.0Rating (451+ reviews)
1,845+Verified Hours
54.5%Score 5s

Book a Session ($150/hr) →

5-session packages at $125/hr. Venmo, Zelle, PayPal, or credit card.

Frequently Asked Questions

What does 2019 AP CSA FRQ 4 LightBoard test?

FRQ 4 tests 2D boolean array construction (with Math.random() for 40% probability initialization) and column traversal with multi-rule conditional evaluation.

How many points is FRQ 4 worth?

9 points: 4 for Part A (constructor) and 5 for Part B (evaluateLight).

How do you get a 40% probability in a boolean assignment?

Math.random() returns a random double in [0.0, 1.0). Comparing it to 0.4 gives true 40% of the time: lights[r][c] = Math.random() < 0.4;

Does the on-count in evaluateLight include the current light?

Yes. Count all lights in column col that are on, including lights[row][col] itself if it is on.

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]