From 34ca7f65af921e92af062fdc7f36fb79c3e26898 Mon Sep 17 00:00:00 2001 From: Zach Date: Fri, 2 Jul 2021 16:15:56 -0400 Subject: [PATCH] All test cases passed --- BlueJ.FirstSaturday.iml | 21 +++++ WriteIFs.java | 82 +++++++++++------- WriteLoops.java | 84 ++++++++++++++----- out/production/BlueJ.FirstSaturday/.gitignore | 25 ++++++ .../.vscode/launch.test.json | 10 +++ .../BlueJ.FirstSaturday.iml | 21 +++++ out/production/BlueJ.FirstSaturday/README.TXT | 23 +++++ out/production/BlueJ.FirstSaturday/README.md | 19 +++++ .../BlueJ.FirstSaturday/package.bluej | 67 +++++++++++++++ package.bluej | 38 +++++---- 10 files changed, 322 insertions(+), 68 deletions(-) create mode 100644 BlueJ.FirstSaturday.iml create mode 100644 out/production/BlueJ.FirstSaturday/.gitignore create mode 100644 out/production/BlueJ.FirstSaturday/.vscode/launch.test.json create mode 100644 out/production/BlueJ.FirstSaturday/BlueJ.FirstSaturday.iml create mode 100644 out/production/BlueJ.FirstSaturday/README.TXT create mode 100644 out/production/BlueJ.FirstSaturday/README.md create mode 100644 out/production/BlueJ.FirstSaturday/package.bluej diff --git a/BlueJ.FirstSaturday.iml b/BlueJ.FirstSaturday.iml new file mode 100644 index 0000000..c02b99a --- /dev/null +++ b/BlueJ.FirstSaturday.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..9b7a02d 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -7,10 +7,47 @@ */ public class WriteIFs { + int tt_s = 1; + int x = 0; + int tt_t = 0; + String ss = ""; + int oo1 = 61; + int oo2 = 49; + public boolean isAlive(boolean p) { + return !p; + } + private int tempurature(int t) { + return t+2; + } + private void heatOn() { + this.ss = "heating"; + } + private void coolOn() { + this.ss = "cooling"; + } + + private int insideTemp() { + return oo1; + } + private int outsideTemp() { + return oo2; + } + private void startAFire(Object o) { + this.tt_s = 213; + } + private void refuel() { + this.x = 99; + } + private void displayGameOver(boolean b) { + this.ss = "Game Over!"; + } public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” + if(!isAlive(player1)){ + displayGameOver(player1); + } } @@ -18,7 +55,11 @@ public String thermoSTAT(int room) { // Write an IF statement that checks the // “temperature(room)” and if that check is less than 70, // calls “heatOn()” else calls “coolOn()” - + if(tempurature(room) < 70){ + heatOn(); + } else { + coolOn(); + } return this.ss; @@ -30,13 +71,17 @@ public void fireplaceControl(Object fireplace1) { // AND // “insideTemp()” is less than 62, // calls “startAFire(fireplace1)” - + if(outsideTemp() < 50 && insideTemp() < 62){ + startAFire(fireplace1); + } } public void checkFuel(double fuelLevel) { // Write an IF statement that checks “fuelLevel” // and if that check is less than 0.08, calls “refuel()” - + if(fuelLevel < .08) { + refuel(); + } } @@ -67,34 +112,7 @@ public WriteIFs() oo1 = 61; oo2 = 49; } +// associated routines - // associated routines - public boolean isAlive(boolean p) { - return !p; - } - private int tempurature(int t) { - return t+2; - } - private void heatOn() { - this.ss = "heating"; - } - private void coolOn() { - this.ss = "cooling"; - } - - private int insideTemp() { - return oo1; - } - private int outsideTemp() { - return oo2; - } - private void startAFire(Object o) { - this.tt_s = 213; - } - private void refuel() { - this.x = 99; - } - private void displayGameOver(boolean b) { - this.ss = "Game Over!"; - } + } diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..0cda853 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -1,4 +1,4 @@ -import com.sun.org.apache.xpath.internal.SourceTree; + import java.awt.SystemTray; import java.util.concurrent.ThreadLocalRandom; @@ -20,7 +20,10 @@ public int oneToFive() { // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + + for(int i = 0; i < 5; i++){ + w = w + 1; + } // each time through the loop // this will tell the test how many times the loop executed. @@ -32,7 +35,9 @@ public int oneToTen() { // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + for(int i = 0; i < 10; i++){ + w = w + 1; + } // each time through the loop return w; @@ -43,7 +48,10 @@ public int startAtTwentyOne() { // Write a FOR loop that makes 10 iterations, start at 21. // calling - w = w + 1; + + for(int i = 21; i >=1; i-=2){ + w = w + 1; + } // each time through the loop return w; @@ -54,7 +62,10 @@ public int countDown() { // Write a FOR loop that counts down from 100 to 0. // calling - w = w + 1; + + for(int i = 100; i > 0; i--){ + w = w + 1; + } // each time through the loop return w; @@ -65,7 +76,10 @@ public int byTwoTo32() { // Write a FOR loop from 0 to 32 by 2s. // calling - w = w + 1; + for(int i = 0; i <= 32; i += 2){ + w = w + 1; + } + // each time through the loop return w; } @@ -75,7 +89,9 @@ public int countDownFrom5000() { // Write a FOR loop from 1 to less than 5001 by 11s. // calling - w = w + 1; + for(int i = 1; i <5001; i += 11){ + w = w + 1; + } // each time through the loop return w; @@ -87,7 +103,12 @@ public int nestedFors() { // Write a nested FOR loop(s), where one counts from // 0 to less than 20 and the inner one counts from 0 to 4 // calling - w = w + 1; + for(int i = 0; i < 20; i++){ + for(int j = 0; j <=4; j++){ + w = w + 1; + } + } + // each time through the inner loop return w; @@ -102,7 +123,13 @@ public int helloZipCode() { // prints “Hello Zipcode” instead of the statement w = w + 1; // calling - w = w + 1; + for(int i = 5; i < 105; i++){ + if(i > 51){ + System.out.println("Hello Zipcode"); + } else { + w = w + 1; + } + } // each time through the inner loop return w; @@ -133,12 +160,13 @@ public int driveHome() { int w = 0; // you need to use a .equals for two Strings. - + while(gpsCurrentLocation().equals("Not Home")){ // calling + driveSomeMore(); w = w + 1; // each time through the inner loop - - + } + System.out.println("Honey, I'm Home!"); return w; } @@ -148,19 +176,23 @@ public int driveHome() { // is less than “highestScore” and if it is, adds “currentScore” to // "runningScore" // and then sets “currentScore” to “gameNextScore()” - public int checkGameScore() { + public boolean checkGameScore() { int w = 0; int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0; // do your while loop here - + while(runningScore < highestScore){ + runningScore = currentScore; + currentScore = gameNextScore(); + w = w + 1; + } // calling - w = w + 1; + // each time through the inner loop - return w; // >= 3; + return w >= 3; } // Rewrite the previous WHILE loop as a DO..WHILE loop. @@ -172,9 +204,14 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; // do your while loop here - + do{ + runningScore += currentScore; + currentScore = gameNextScore(); + w = w + 1; + } while(runningScore < highestScore); + // calling - w = w + 1; + // each time through the inner loop return w >= 3; @@ -188,9 +225,16 @@ public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - + while(serverIsRunning()){ + waitFor(5); + w = w + 1; + } + if(!serverIsRunning()){ + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Help", adminPhoneNumber); + } // calling - w = w + 1; + // each time through the inner loop return w; diff --git a/out/production/BlueJ.FirstSaturday/.gitignore b/out/production/BlueJ.FirstSaturday/.gitignore new file mode 100644 index 0000000..c28a9d8 --- /dev/null +++ b/out/production/BlueJ.FirstSaturday/.gitignore @@ -0,0 +1,25 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.idea/* \ No newline at end of file diff --git a/out/production/BlueJ.FirstSaturday/.vscode/launch.test.json b/out/production/BlueJ.FirstSaturday/.vscode/launch.test.json new file mode 100644 index 0000000..64ebee9 --- /dev/null +++ b/out/production/BlueJ.FirstSaturday/.vscode/launch.test.json @@ -0,0 +1,10 @@ +{ + "run": { + "default": "", + "items": [] + }, + "debug": { + "default": "", + "items": [] + } +} \ No newline at end of file diff --git a/out/production/BlueJ.FirstSaturday/BlueJ.FirstSaturday.iml b/out/production/BlueJ.FirstSaturday/BlueJ.FirstSaturday.iml new file mode 100644 index 0000000..c02b99a --- /dev/null +++ b/out/production/BlueJ.FirstSaturday/BlueJ.FirstSaturday.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/BlueJ.FirstSaturday/README.TXT b/out/production/BlueJ.FirstSaturday/README.TXT new file mode 100644 index 0000000..4652f8f --- /dev/null +++ b/out/production/BlueJ.FirstSaturday/README.TXT @@ -0,0 +1,23 @@ +FIRST SATURDAY +============== + +Lab Brief +--------- + +The objective of this lab is to give you an opportunity to think through IF statements +and LOOPS (WHILE, DO WHILE, and FOR). + +You will need to read the TEST classes first, to get a feel for what you have to write +for the CODE classes. + +Work through code class WriteIFs.java, follow the directions for each method. +Run All Tests on the class until you pass them all. + +Work through code class WriteLoops.java, follow the directions for each method. +Run All Tests on the class until you pass them all. For each of the loop methods, +you need to put the code about w = w + 1; inside of the loops. It lets the test know how +many iterations of the loop your code did. This data is used to make sure you passed the tests. + +You may not change ANY existing test methods. You get extra credit(!) for each test you add. + +Be sure to pass all the tests with your code. \ No newline at end of file diff --git a/out/production/BlueJ.FirstSaturday/README.md b/out/production/BlueJ.FirstSaturday/README.md new file mode 100644 index 0000000..b3d3a5e --- /dev/null +++ b/out/production/BlueJ.FirstSaturday/README.md @@ -0,0 +1,19 @@ +* This lab has been separated into several labs: + * [ControlsChecker.BlueJ](https://github.com/Zipcoder/controlschecker.bluej) + * [ThresholdEvaluator.BlueJ](https://github.com/Zipcoder/thresholdevaluator.bluej) + * more to come... + +# First Saturday + +First weekend lab. Overall idea is to read the code, read the tests, and then write some code to pass all the tests. + +Be sure to commit all your changes multiple times as you're working on the lab. + +`git commit -m "checkpointing my work"` should do, be sure to change the message to something meaningful to the work you're saving. + +When you are finished, and are passing all the tests, be sure to do a final `git commit` and then do a `Pull Request` so we can review your work. + + + + +now see [README.TXT](README.TXT). diff --git a/out/production/BlueJ.FirstSaturday/package.bluej b/out/production/BlueJ.FirstSaturday/package.bluej new file mode 100644 index 0000000..f89f32c --- /dev/null +++ b/out/production/BlueJ.FirstSaturday/package.bluej @@ -0,0 +1,67 @@ +#BlueJ package file +dependency1.from=WriteLoopsTest +dependency1.to=WriteLoops +dependency1.type=UsesDependency +dependency2.from=WriteIFsTest +dependency2.to=WriteIFs +dependency2.type=UsesDependency +editor.fx.0.height=722 +editor.fx.0.width=800 +editor.fx.0.x=525 +editor.fx.0.y=45 +objectbench.height=107 +objectbench.width=1241 +package.divider.horizontal=0.6 +package.divider.vertical=0.8496042216358839 +package.editor.height=637 +package.editor.width=1147 +package.editor.x=112 +package.editor.y=23 +package.frame.height=816 +package.frame.width=1265 +package.numDependencies=2 +package.numTargets=5 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +readme.height=60 +readme.name=@README +readme.width=48 +readme.x=10 +readme.y=10 +target1.height=110 +target1.name=WriteLoopsTest +target1.showInterface=false +target1.type=UnitTestTargetJunit4 +target1.width=100 +target1.x=170 +target1.y=330 +target2.association=WriteLoopsTest +target2.height=110 +target2.name=WriteLoops +target2.showInterface=false +target2.type=ClassTarget +target2.width=100 +target2.x=140 +target2.y=360 +target3.height=110 +target3.name=WriteIFsTest +target3.showInterface=false +target3.type=UnitTestTargetJunit4 +target3.width=80 +target3.x=180 +target3.y=100 +target4.association=WriteIFsTest +target4.height=110 +target4.name=WriteIFs +target4.showInterface=false +target4.type=ClassTarget +target4.width=80 +target4.x=150 +target4.y=130 +target5.height=70 +target5.name=README.md +target5.type=TextTarget +target5.width=120 +target5.x=70 +target5.y=10 diff --git a/package.bluej b/package.bluej index 01992ee..c6d911e 100644 --- a/package.bluej +++ b/package.bluej @@ -7,41 +7,41 @@ dependency2.to=WriteIFs dependency2.type=UsesDependency editor.fx.0.height=722 editor.fx.0.width=800 -editor.fx.0.x=560 -editor.fx.0.y=118 -objectbench.height=101 -objectbench.width=740 +editor.fx.0.x=463 +editor.fx.0.y=48 +objectbench.height=107 +objectbench.width=1241 package.divider.horizontal=0.6 -package.divider.vertical=0.8625954198473282 -package.editor.height=671 -package.editor.width=1139 +package.divider.vertical=0.8496042216358839 +package.editor.height=637 +package.editor.width=1147 package.editor.x=112 -package.editor.y=89 -package.frame.height=844 +package.editor.y=23 +package.frame.height=816 package.frame.width=1265 package.numDependencies=2 -package.numTargets=4 +package.numTargets=5 package.showExtends=true package.showUses=true project.charset=UTF-8 -readme.height=58 +readme.height=60 readme.name=@README -readme.width=47 +readme.width=48 readme.x=10 readme.y=10 -target1.height=110 +target1.height=130 target1.name=WriteLoopsTest target1.showInterface=false target1.type=UnitTestTargetJunit4 -target1.width=100 +target1.width=120 target1.x=170 target1.y=330 target2.association=WriteLoopsTest -target2.height=110 +target2.height=130 target2.name=WriteLoops target2.showInterface=false target2.type=ClassTarget -target2.width=100 +target2.width=120 target2.x=140 target2.y=360 target3.height=110 @@ -59,3 +59,9 @@ target4.type=ClassTarget target4.width=80 target4.x=150 target4.y=130 +target5.height=70 +target5.name=README.md +target5.type=TextTarget +target5.width=120 +target5.x=70 +target5.y=10