Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
github-classroom[bot] authored Apr 30, 2024
0 parents commit 201223e
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
.gradle/
21 changes: 21 additions & 0 deletions README.md
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
```
18 changes: 18 additions & 0 deletions build.gradle
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"
}
}
47 changes: 47 additions & 0 deletions src/main/java/LightBoard.java
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;
}

}
17 changes: 17 additions & 0 deletions src/main/java/Main.java
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();
}
}
49 changes: 49 additions & 0 deletions src/test/java/Tester.java
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;
}


}

0 comments on commit 201223e

Please sign in to comment.