generated from APCSLowell/2019A4-LightBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,57 @@ | ||
# 2019 AP Computer Science A FRQ #4 LightBoard | ||
Instructions: https://apstudents.collegeboard.org/ap/pdf/ap19-frq-computer-science-a.pdf | ||
public class LightBoard | ||
{ | ||
/** The lights on the board, where true represents on and false represents | ||
* off. | ||
*/ | ||
private boolean[][] lights; | ||
/** Constructs a LightBoard object having numRows rows and numCols columns. | ||
* Precondition: numRows > 0, numCols > 0 | ||
* Postcondition: each light has a 40% probability of being set to on. | ||
*/ | ||
public LightBoard(int numRows, int numCols) | ||
{ | ||
/* to be implemented in part (a) */ | ||
} | ||
/** Evaluates a light in row index row and column index col and returns a | ||
* status as described in part (b). | ||
* Precondition: row and col are valid indexes in lights. | ||
*/ | ||
public boolean evaluateLight(int row, int col) | ||
{ | ||
/* to be implemented in part (b) */ | ||
} | ||
// There may be additional instance variables, constructors, and methods not | ||
// shown. | ||
} | ||
|
||
Quick Reference Guide: https://apstudents.collegeboard.org/ap/pdf/ap-computer-science-a-java-quick-reference.pdf | ||
public LightBoard(int numRows, int numCols) | ||
{ | ||
lights = new boolean[numRows][numCols]; | ||
|
||
The correct answer outputs should have a pattern of 7 rows and 5 columns of stars and dots **_similar_** to that shown and should match the last line exactly. | ||
for(int r = 0; r < lights.length; r++) | ||
for(int c = 0; c < lights[0].length; c++) | ||
if(Math.random() <= 0.4) | ||
lights[r][c] = true; | ||
} | ||
|
||
|
||
public boolean evaluateLight(int row, int col) | ||
{ | ||
int onInColumn = 0; | ||
|
||
``` | ||
**.*. | ||
***.. | ||
.**.. | ||
****. | ||
**... | ||
..... | ||
....* | ||
for(int r = 0; r < lights.length; r++) | ||
if(lights[r][col]) | ||
onInColumn++; | ||
|
||
if(lights[row][col]) | ||
{ | ||
if(onInColumn % 2 == 0) | ||
return false; | ||
} | ||
else | ||
{ | ||
if(onInColumn % 3 == 0) | ||
return true; | ||
} | ||
|
||
false true false true | ||
``` | ||
return lights[row][col]; | ||
} |