Part A:

Write the constructor for the LightBoard class, which initializes lights so that each light is set to on with a 40% probability. The notation lights[r][c] represents the array element at row r and column c.

The first line instantiates and sizes lights to numRows rows and numCols columns. The code then iterates through each cell in the matrix and uses Math.random to meet the 40% probability requirement.

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++) {
            double rnd = Math.random();
            lights[r][c] = rnd < 0.4;
        }
    }
}

Part B:

Write the method evaluateLight, which computes and returns the status of a light at a given row and column based on the following rules.

The variable OnCount is used to keep track of the number of lights that are on in each column.

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];
}