ggadget6

AP CS A 2019 FRQ #4

Dec 18th, 2019
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public LightBoard(int numRows, int numCols) {
  2.   lights = new boolean[numRows][numCols];
  3.  
  4.   for(int i = 0; i < numRows; i++) {
  5.     for(int j = 0; j < numCols; j++) {
  6.       boolean temp = Math.random() < .4;
  7.       lights[i][j] = temp;
  8.     }
  9.   }
  10. }
  11.  
  12. public boolean evaluateLight(int row, int col) {
  13.   int numLights = 0;
  14.   for(int i = 0; i < lights.length; i++) {
  15.     if(lights[i][col]) {
  16.       numLights++;
  17.     }
  18.   }
  19.   if(lights[row][col]) {
  20.     return (numLights % 2 == 1);
  21.   }
  22.   else {
  23.     return (numLights % 3 == 0);
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment