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
0 parents
commit 201223e
Showing
6 changed files
with
154 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
.gradle/ |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 2019 AP Computer Science A FRQ #4 LightBoard | ||
Instructions: https://apstudents.collegeboard.org/ap/pdf/ap19-frq-computer-science-a.pdf | ||
|
||
Quick Reference Guide: https://apstudents.collegeboard.org/ap/pdf/ap-computer-science-a-java-quick-reference.pdf | ||
|
||
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. | ||
|
||
|
||
|
||
``` | ||
**.*. | ||
***.. | ||
.**.. | ||
****. | ||
**... | ||
..... | ||
....* | ||
false true false true | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0') | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
testLogging { | ||
events "passed", "skipped", "failed" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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) */ | ||
|
||
|
||
} | ||
public boolean[][] getLights() | ||
{ | ||
return lights; | ||
} | ||
//used for testing | ||
public String toString() | ||
{ | ||
String s = ""; | ||
for (int r = 0; r < lights.length; r++) | ||
{ | ||
for (int c = 0; c < lights[0].length; c++) | ||
if (lights[r][c]) | ||
s += "*"; | ||
else | ||
s += "."; | ||
s += "\n"; | ||
} | ||
return s; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Main { | ||
public static void main(String[] args) | ||
{ | ||
LightBoard sim = new LightBoard(7, 5); | ||
System.out.println(sim); | ||
System.out.println(); | ||
|
||
String[] stars = {"**.**", "*..*.", "*..**", "*...*", "*...*", "**.**", "....."}; | ||
boolean[][] lights = sim.getLights(); | ||
for (int r = 0; r < stars.length; r++) | ||
for (int c = 0; c < stars[0].length(); c++) | ||
lights[r][c] = stars[r].charAt(c) == '*'; | ||
System.out.println(sim.evaluateLight(0, 3) + " " + sim.evaluateLight(6, 0) + " " + | ||
sim.evaluateLight(4, 1) + " " + sim.evaluateLight(5, 4)); | ||
System.out.println(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import java.io.*; | ||
|
||
public class Tester { | ||
|
||
@Test | ||
public void partA () { | ||
LightBoard test = new LightBoard(500,650); | ||
int rows = test.getLights().length; | ||
int cols = test.getLights()[0].length; | ||
assertEquals(500,rows); | ||
assertEquals(650,cols); | ||
// double count = 0; | ||
// for(int r = 0; r < rows;r++) | ||
// for(int c = 0; c < cols; c++) | ||
// if(test.getLights()[r][c]) | ||
// count++; | ||
// assertEquals(0.4,count/(rows*cols),0.2); | ||
// Don't think you can test this since it's random | ||
} | ||
|
||
@Test | ||
public void partB(){ | ||
LightBoard test = new LightBoard(7,5); | ||
String[] stars = {"**.**", "*..*.", "*..**", "*...*", "*...*", "**.**", "....."}; | ||
boolean[][] newLights = test.getLights(); | ||
for (int r = 0; r < stars.length; r++) | ||
for (int c = 0; c < stars[0].length(); c++) | ||
newLights[r][c] = stars[r].charAt(c) == '*'; | ||
assertEquals(false,test.evaluateLight(0, 3),partBFail(false,0,3)); | ||
assertEquals(true,test.evaluateLight(6, 0),partBFail(true,6,0)); | ||
assertEquals(false,test.evaluateLight(4, 1),partBFail(false,4,1)); | ||
assertEquals(true,test.evaluateLight(5, 4),partBFail(true,5,4)); | ||
} | ||
|
||
private String partBFail(boolean expected, int num1, int num2){ | ||
return "Expected " + expected + " with evaluateLight(" + num1 + "," + num2 + "), but output was " + !expected; | ||
} | ||
|
||
|
||
} |