From 74d0aef7425fbc71a1fe197ae59aa89029224602 Mon Sep 17 00:00:00 2001 From: smartist17 <79124739+smartist17@users.noreply.github.com> Date: Wed, 3 Mar 2021 22:35:06 -0500 Subject: [PATCH 1/2] Completing first saturday --- WriteIFs.java | 20 ++++++++++++-- WriteLoops.java | 69 +++++++++++++++++++++++++++++++++++++------------ package.bluej | 26 +++++++++---------- 3 files changed, 83 insertions(+), 32 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..58c68e2 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -9,12 +9,20 @@ public class WriteIFs { public void playerDied(boolean player1) { + if (!isAlive(player1)) { + displayGameOver(player1); + } // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - + } public String thermoSTAT(int room) { + if (tempurature(room) < 70) { + heatOn(); + } else { + coolOn(); + } // Write an IF statement that checks the // “temperature(room)” and if that check is less than 70, // calls “heatOn()” else calls “coolOn()” @@ -25,6 +33,10 @@ public String thermoSTAT(int room) { } public void fireplaceControl(Object fireplace1) { + if (outsideTemp() < 50 && insideTemp() < 62) { + startAFire(fireplace1); + } + // Write an IF statement that checks // “outsideTemp()” is less than 50 // AND @@ -34,6 +46,9 @@ public void fireplaceControl(Object fireplace1) { } public void checkFuel(double fuelLevel) { + if (fuelLevel < 0.08) { + refuel(); + } // Write an IF statement that checks “fuelLevel” // and if that check is less than 0.08, calls “refuel()” @@ -46,7 +61,8 @@ public void checkFuel(double fuelLevel) { * * * instance variables - * / + */ + int x; int tt_t; int tt_s; diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..fffb80e 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -1,4 +1,4 @@ -import com.sun.org.apache.xpath.internal.SourceTree; +//import com.sun.org.apache.xpath.internal.SourceTree; import java.awt.SystemTray; import java.util.concurrent.ThreadLocalRandom; @@ -17,10 +17,14 @@ public class WriteLoops { public int oneToFive() { int w = 0; - + for (int count = 1; count <= 5; count++) { + w = w + 1; + } + + // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + // each time through the loop // this will tell the test how many times the loop executed. @@ -29,10 +33,13 @@ public int oneToFive() { public int oneToTen() { int w = 0; + for (int count=1; count <= 10; count++){ + w = w + 1; + } // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + // each time through the loop return w; @@ -40,10 +47,13 @@ public int oneToTen() { public int startAtTwentyOne() { int w = 0; + for (int i = 21; i > 10; i--){ + w = w + 1; + } // Write a FOR loop that makes 10 iterations, start at 21. // calling - w = w + 1; + // each time through the loop return w; @@ -51,10 +61,13 @@ public int startAtTwentyOne() { public int countDown() { int w = 0; - + for (int i = 100; i > 0; i--){ + w = w + 1; + } + // Write a FOR loop that counts down from 100 to 0. // calling - w = w + 1; + // each time through the loop return w; @@ -62,20 +75,26 @@ public int countDown() { public int byTwoTo32() { int w = 0; + for (int i= 0; i <=32; i+=2){ + w = w + 1; + } // Write a FOR loop from 0 to 32 by 2s. // calling - w = w + 1; + // each time through the loop return w; } public int countDownFrom5000() { int w = 0; + for (int i=1; i < 5001; i+=11){ + w = w + 1; + } // Write a FOR loop from 1 to less than 5001 by 11s. // calling - w = w + 1; + // each time through the loop return w; @@ -83,11 +102,18 @@ public int countDownFrom5000() { public int nestedFors() { int w = 0; + for (int i = 0; i < 20; i++){ + for (int j= 0; j <= 4; j++){ + w = w + 1; + + } + + } // 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; + // each time through the inner loop return w; @@ -95,6 +121,13 @@ public int nestedFors() { public int helloZipCode() { int w = 0; + for (int i=5; i <= 105; i++){ + if (i > 51) { + System.out.print("Hello Zipcode"); + } else { + w = w + 1; + } + } // Write a FOR loop that counts from 5 to 105. Put an IF // statement inside the loop that checks the @@ -102,7 +135,7 @@ public int helloZipCode() { // prints “Hello Zipcode” instead of the statement w = w + 1; // calling - w = w + 1; + // each time through the inner loop return w; @@ -129,17 +162,19 @@ public void simpleLoops() { // Write a WHILE loop that checks “gpsCurrentLocation()” // and if that is not equal to “Home” then and it calls “driveSomeMore()”. // After the loop is done, print “Honey, I’m Home!” - public int driveHome() { + public int driveHome() { int w = 0; - + while (gpsCurrentLocation() != "Home"){ + driveSomeMore(); + w = w + 1; // you need to use a .equals for two Strings. // calling - w = w + 1; + // each time through the inner loop - - - return w; + System.out.println("Honey, I'm Home!"); + + } return w; } // Getting harder... diff --git a/package.bluej b/package.bluej index 01992ee..d67f12d 100644 --- a/package.bluej +++ b/package.bluej @@ -5,20 +5,20 @@ 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=560 -editor.fx.0.y=118 -objectbench.height=101 -objectbench.width=740 +editor.fx.0.height=642 +editor.fx.0.width=715 +editor.fx.0.x=606 +editor.fx.0.y=23 +objectbench.height=94 +objectbench.width=620 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.8346972176759411 +package.editor.height=503 +package.editor.width=526 +package.editor.x=28 +package.editor.y=41 +package.frame.height=669 +package.frame.width=644 package.numDependencies=2 package.numTargets=4 package.showExtends=true From 1b4801def7c79c534f09fcadc494e2bd2e0562c5 Mon Sep 17 00:00:00 2001 From: smartist17 <79124739+smartist17@users.noreply.github.com> Date: Fri, 5 Mar 2021 18:19:27 -0500 Subject: [PATCH 2/2] First Saturday Complete --- package.bluej | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/package.bluej b/package.bluej index d67f12d..3330a19 100644 --- a/package.bluej +++ b/package.bluej @@ -1,22 +1,22 @@ #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=642 -editor.fx.0.width=715 -editor.fx.0.x=606 -editor.fx.0.y=23 -objectbench.height=94 +editor.fx.0.height=0 +editor.fx.0.width=0 +editor.fx.0.x=0 +editor.fx.0.y=0 +objectbench.height=85 objectbench.width=620 package.divider.horizontal=0.6 -package.divider.vertical=0.8346972176759411 -package.editor.height=503 +package.divider.vertical=0.8494271685761048 +package.editor.height=512 package.editor.width=526 -package.editor.x=28 -package.editor.y=41 +package.editor.x=273 +package.editor.y=23 package.frame.height=669 package.frame.width=644 package.numDependencies=2