From ce8f4c52df0f16da41aabee0f407ebc37554460b Mon Sep 17 00:00:00 2001 From: Dannylui58 <143028255+Dannylui58@users.noreply.github.com> Date: Mon, 29 Apr 2024 22:20:11 -0700 Subject: [PATCH] Update LightBoard.java --- src/main/java/LightBoard.java | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/LightBoard.java b/src/main/java/LightBoard.java index 83df049..16a3e32 100644 --- a/src/main/java/LightBoard.java +++ b/src/main/java/LightBoard.java @@ -1,3 +1,4 @@ + public class LightBoard { /** The lights on the board, where true represents on and false represents off. @@ -10,7 +11,16 @@ public class LightBoard */ public LightBoard(int numRows, int numCols) { - /* to be implemented in part (a) */ + lights = new boolean[numRows][numCols]; + for(int r = 0; r < numRows; r++){ + for(int c = 0; c < numCols; c++){ + double onOrOff = Math.random(); + if(onOrOff < 0.4) + lights[r][c] = true; + else + lights[r][c] = false; + } + } } @@ -20,10 +30,20 @@ public LightBoard(int numRows, int numCols) */ public boolean evaluateLight(int row, int col) { - /* to be implemented in part (b) */ + int count = 0; + for(int i = 0; i < lights.length; i++){ + if(lights[i][col] == true) + count++; + } + if(lights[row][col] == true && count%2 == 0) + return false; + if(lights[row][col] == false && count%3 == 0) + return true; + return lights[row][col]; + } - } + public boolean[][] getLights() { return lights;