From 201223e61538040ee7a628a7719883848fb11168 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Tue, 30 Apr 2024 05:09:36 +0000 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ README.md | 21 +++++++++++++++ build.gradle | 18 +++++++++++++ src/main/java/LightBoard.java | 47 +++++++++++++++++++++++++++++++++ src/main/java/Main.java | 17 ++++++++++++ src/test/java/Tester.java | 49 +++++++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 build.gradle create mode 100644 src/main/java/LightBoard.java create mode 100644 src/main/java/Main.java create mode 100644 src/test/java/Tester.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f2a078 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +.gradle/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..f9672ac --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..7cccf6c --- /dev/null +++ b/build.gradle @@ -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" + } +} diff --git a/src/main/java/LightBoard.java b/src/main/java/LightBoard.java new file mode 100644 index 0000000..83df049 --- /dev/null +++ b/src/main/java/LightBoard.java @@ -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; + } + +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..38fbad1 --- /dev/null +++ b/src/main/java/Main.java @@ -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(); + } +} diff --git a/src/test/java/Tester.java b/src/test/java/Tester.java new file mode 100644 index 0000000..1ccc0b0 --- /dev/null +++ b/src/test/java/Tester.java @@ -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; + } + + +}