From b9ab6647ce9cbdb564fbffc910117b252c499404 Mon Sep 17 00:00:00 2001 From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com> Date: Thu, 1 Jul 2021 20:16:58 -0400 Subject: [PATCH 1/4] player died and thermo stat --- WriteIFs.java | 31 ++++++++++++++++++++++--------- WriteLoops.java | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..ef135e0 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -8,17 +8,34 @@ public class WriteIFs { + int x; + int tt_t; + int tt_s; + int oo1, oo2; + String ss; + public void playerDied(boolean player1) { - // Write an IF statement that checks “player1.isAlive()” + // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - - } + if (isAlive(player1) !=true);{ + displayGameOver(player1); + } + + } + + + + 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 (room < 70) { + heatOn(); + } + else coolOn(); + return this.ss; @@ -47,11 +64,7 @@ public void checkFuel(double fuelLevel) { * * instance variables * / - int x; - int tt_t; - int tt_s; - int oo1, oo2; - String ss; + /** diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..5d8f5eb 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; From 33daa1c119fd84309431e0b618e621b5ff7e6d6c Mon Sep 17 00:00:00 2001 From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com> Date: Thu, 1 Jul 2021 20:49:17 -0400 Subject: [PATCH 2/4] All WriteIftests are passing --- WriteIFs.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/WriteIFs.java b/WriteIFs.java index ef135e0..73b4fb5 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -17,7 +17,7 @@ public class WriteIFs public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - if (isAlive(player1) !=true);{ + if (isAlive(player1) !=true){ displayGameOver(player1); } @@ -47,12 +47,20 @@ 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 < 0.08) { + refuel(); + } } From e5ed3064dd51bbf881e2ec7826a6324d006b83e3 Mon Sep 17 00:00:00 2001 From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com> Date: Fri, 2 Jul 2021 14:30:04 -0400 Subject: [PATCH 3/4] up to while loop, and the tests are passing --- WriteLoops.java | 68 +++++++++++++++++++++++++++++++++++++------------ package.bluej | 42 +++++++++++++++++------------- 2 files changed, 76 insertions(+), 34 deletions(-) diff --git a/WriteLoops.java b/WriteLoops.java index 5d8f5eb..1419b1f 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -17,10 +17,15 @@ public class WriteLoops { public int oneToFive() { int w = 0; + w = w + 1; //acts as counter + for (int i = 1; i < 5; i++) { + w++; + + } - // Write a FOR loop that counts from 1 to 10. + // Write a FOR loop that counts from 1 to 5. // calling - w = w + 1; + //w = w + 1; // each time through the loop // this will tell the test how many times the loop executed. @@ -29,10 +34,13 @@ public int oneToFive() { public int oneToTen() { int w = 0; - + w = w + 1; + for (int i = 1; i < 10; i++) { + w++; + } // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + //w = w + 1; // each time through the loop return w; @@ -40,10 +48,12 @@ public int oneToTen() { public int startAtTwentyOne() { int w = 0; - + for (int i = 21; i <= 31; i++) { + w++; + } // Write a FOR loop that makes 10 iterations, start at 21. // calling - w = w + 1; + //w = w + 1; // each time through the loop return w; @@ -51,31 +61,39 @@ public int startAtTwentyOne() { public int countDown() { int w = 0; + for (int i = 100; i > 0; i--) { + w++; + } // Write a FOR loop that counts down from 100 to 0. // calling - w = w + 1; + //w = w + 1; // each time through the loop return w; } public int byTwoTo32() { - int w = 0; - + int w = 0; + for (int i = 0; i <= 32; i+=2) { + w++; + } // Write a FOR loop from 0 to 32 by 2s. // calling - w = w + 1; + //w = w + 1; // each time through the loop return w; } public int countDownFrom5000() { int w = 0; + for (int i = 5001; i > 1; i -= 11) { + w++; + } // Write a FOR loop from 1 to less than 5001 by 11s. // calling - w = w + 1; + //w = w + 1; // each time through the loop return w; @@ -83,11 +101,16 @@ public int countDownFrom5000() { public int nestedFors() { int w = 0; + for (int i = 0; i < 20; i++) { + for (int j = 0; j <= 4; j++) { + w++; + } + } // 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; + //w = w + 1; this is the same as w++ // each time through the inner loop return w; @@ -95,6 +118,13 @@ public int nestedFors() { public int helloZipCode() { int w = 0; + for (int i = 5; i <= 105; i++) { + if (i > 51){ + System.out.println("Hello Zipcode"); + } + else w++; + } + // Write a FOR loop that counts from 5 to 105. Put an IF // statement inside the loop that checks the @@ -102,7 +132,7 @@ public int helloZipCode() { // prints “Hello Zipcode” instead of the statement w = w + 1; // calling - w = w + 1; + //w = w + 1; // each time through the inner loop return w; @@ -131,14 +161,20 @@ public void simpleLoops() { // After the loop is done, print “Honey, I’m Home!” public int driveHome() { int w = 0; + + while (gpsCurrentLocation() != "Home"){ + driveSomeMore(); + w = w + 1; + } + System.out.println("Honey, I'm Home!"); + // you need to use a .equals for two Strings. // calling - w = w + 1; + // each time through the inner loop - - + return w; } diff --git a/package.bluej b/package.bluej index 01992ee..e645548 100644 --- a/package.bluej +++ b/package.bluej @@ -1,32 +1,32 @@ #BlueJ package file -dependency1.from=WriteLoopsTest -dependency1.to=WriteLoops +dependency1.from=WriteIFsTest +dependency1.to=WriteIFs dependency1.type=UsesDependency -dependency2.from=WriteIFsTest -dependency2.to=WriteIFs +dependency2.from=WriteLoopsTest +dependency2.to=WriteLoops dependency2.type=UsesDependency -editor.fx.0.height=722 +editor.fx.0.height=977 editor.fx.0.width=800 -editor.fx.0.x=560 -editor.fx.0.y=118 +editor.fx.0.x=1899 +editor.fx.0.y=-1046 objectbench.height=101 -objectbench.width=740 +objectbench.width=791 package.divider.horizontal=0.6 -package.divider.vertical=0.8625954198473282 -package.editor.height=671 -package.editor.width=1139 -package.editor.x=112 -package.editor.y=89 -package.frame.height=844 -package.frame.width=1265 +package.divider.vertical=0.8423357664233576 +package.editor.height=570 +package.editor.width=697 +package.editor.x=1182 +package.editor.y=0 +package.frame.height=743 +package.frame.width=815 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 @@ -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 From 56bfe6fce90cee4f77429e8409600a9b48be640b Mon Sep 17 00:00:00 2001 From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:09:32 -0400 Subject: [PATCH 4/4] passed all tests --- WriteLoops.java | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/WriteLoops.java b/WriteLoops.java index 1419b1f..67b5110 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -162,7 +162,7 @@ public void simpleLoops() { public int driveHome() { int w = 0; - while (gpsCurrentLocation() != "Home"){ + while (gpsCurrentLocation().equals("Not Home")) { driveSomeMore(); w = w + 1; } @@ -184,19 +184,24 @@ 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 - - // calling - w = w + 1; + while (runningScore < highestScore){ + runningScore = currentScore; + w++; + currentScore = gameNextScore(); + } + + // calling + // each time through the inner loop - return w; // >= 3; + return w >= 3; } // Rewrite the previous WHILE loop as a DO..WHILE loop. @@ -207,10 +212,15 @@ public boolean checkGameScoreDoWhile() { int currentScore = gameNextScore(); int runningScore = 0; + + do { + runningScore = currentScore; + w++; + } while (w > 0); // do your while loop here // calling - w = w + 1; + // each time through the inner loop return w >= 3; @@ -223,10 +233,18 @@ public boolean checkGameScoreDoWhile() { public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; + while (serverIsRunning()) { + waitFor(5); + w++; + } + if (serverIsRunning() != true){ + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Help!", adminPhoneNumber); + + } - // calling - w = w + 1; + // each time through the inner loop return w;