From b845a7b120208c166cb70f485e070ac04bb9ac63 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Fri, 18 Oct 2019 15:58:56 -0400 Subject: [PATCH 1/4] Update --- WriteIFs.java | 43 +++++++++++++++++++++++++++++++++++-------- package.bluej | 38 +++++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..6fd1028 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -7,19 +7,34 @@ */ public class WriteIFs { - + /* int x; + int tt_t; + int tt_s; + String ss; + int oo1, oo2; +*/ public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - + + if (this.isAlive(player1) == false){ + 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(this.tempurature(room) < 70){ + + heatOn(); + } + + else{ + coolOn(); + } + return this.ss; } @@ -30,23 +45,35 @@ public void fireplaceControl(Object fireplace1) { // AND // “insideTemp()” is less than 62, // calls “startAFire(fireplace1)” - + System.out.println("Before: " + this.tt_s); + + if(outsideTemp() < 50 && insideTemp() < 62){ + startAFire(fireplace1); + } + + System.out.println("After: " + this.tt_s); + System.out.println("--------------"); } 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(); + } } - /** + /* * Pay no attention to the code below this point. * * * instance variables - * / + */ int x; int tt_t; int tt_s; @@ -54,7 +81,7 @@ public void checkFuel(double fuelLevel) { String ss; - /** + /* * Constructor for objects of class WriteIFs */ public WriteIFs() diff --git a/package.bluej b/package.bluej index 01992ee..6c50f1a 100644 --- a/package.bluej +++ b/package.bluej @@ -5,20 +5,32 @@ 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=1080 +editor.fx.0.width=954 +editor.fx.0.x=-361 +editor.fx.0.y=-1080 +editor.fx.1.height=1080 +editor.fx.1.width=954 +editor.fx.1.x=-361 +editor.fx.1.y=-1080 +editor.fx.2.height=1080 +editor.fx.2.width=954 +editor.fx.2.x=605 +editor.fx.2.y=-1080 +editor.fx.3.height=1080 +editor.fx.3.width=954 +editor.fx.3.x=605 +editor.fx.3.y=-1080 +objectbench.height=113 +objectbench.width=462 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.8369565217391305 +package.editor.height=609 +package.editor.width=360 +package.editor.x=16 +package.editor.y=36 +package.frame.height=794 +package.frame.width=486 package.numDependencies=2 package.numTargets=4 package.showExtends=true From d6d410bb371148e5fc32c45beda3c4ab2626d23b Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Fri, 18 Oct 2019 16:58:21 -0400 Subject: [PATCH 2/4] Update --- WriteIFs.java | 13 ++++--------- WriteLoops.java | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index 6fd1028..7b6d1e8 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -17,7 +17,7 @@ public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - if (this.isAlive(player1) == false){ + if (isAlive(player1) == false){ displayGameOver(player1); } } @@ -26,7 +26,7 @@ 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(this.tempurature(room) < 70){ + if(tempurature(room) < 70){ heatOn(); } @@ -45,16 +45,12 @@ public void fireplaceControl(Object fireplace1) { // AND // “insideTemp()” is less than 62, // calls “startAFire(fireplace1)” - System.out.println("Before: " + this.tt_s); - + if(outsideTemp() < 50 && insideTemp() < 62){ startAFire(fireplace1); } - - System.out.println("After: " + this.tt_s); - System.out.println("--------------"); } - + public void checkFuel(double fuelLevel) { // Write an IF statement that checks “fuelLevel” // and if that check is less than 0.08, calls “refuel()” @@ -108,7 +104,6 @@ private void heatOn() { private void coolOn() { this.ss = "cooling"; } - private int insideTemp() { return oo1; } diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..86b8856 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; From 9eeac108226359b1d3ee343c5572e5db0c6add72 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Fri, 18 Oct 2019 19:10:43 -0400 Subject: [PATCH 3/4] Update --- WriteLoops.java | 165 ++++++++++++++++++++++++++++++-------------- WriteLoopsTest.java | 52 ++++++++++++++ 2 files changed, 167 insertions(+), 50 deletions(-) diff --git a/WriteLoops.java b/WriteLoops.java index 86b8856..8a5d1b6 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -18,9 +18,12 @@ public class WriteLoops { public int oneToFive() { int w = 0; - // Write a FOR loop that counts from 1 to 10. + // Write a FOR loop that counts from 1 to 5. // calling + for(int i = 1; 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,10 @@ public int oneToTen() { // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + for(int i = 1; i <= 10; i++){ + + w = w + 1; + } // each time through the loop return w; @@ -43,7 +49,11 @@ public int startAtTwentyOne() { // Write a FOR loop that makes 10 iterations, start at 21. // calling - w = w + 1; + for(int i = 21; i <= 31; i++){ + + w = w + 1; + } + // each time through the loop return w; @@ -54,7 +64,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,8 +78,12 @@ 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 + w = 0; return w; } @@ -75,7 +92,10 @@ 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 +107,13 @@ 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 +128,15 @@ public int helloZipCode() { // prints “Hello Zipcode” instead of the statement w = w + 1; // calling + 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; @@ -124,6 +158,8 @@ public void simpleLoops() { i = i - 1; } while (i > 0); // what's the primary difference between them?!? + // The difference is that "while" checks the condition at the beginning of every loop + // while "do...while" checks at the end. } // Write a WHILE loop that checks “gpsCurrentLocation()” @@ -134,12 +170,14 @@ public int driveHome() { // you need to use a .equals for two Strings. - // calling + // callin + while(gpsCurrentLocation().equals("Home") == false){ + driveSomeMore(); w = w + 1; - // each time through the inner loop - - - return w; + } + // each time through the inner loop + //System.out.println("Honey, I'm Home!"); + return w; } // Getting harder... @@ -155,11 +193,13 @@ public int checkGameScore() { int runningScore = 0; // do your while loop here - + while(runningScore < highestScore){ // calling + runningScore +=currentScore; + currentScore = gameNextScore(); w = w + 1; // each time through the inner loop - + } return w; // >= 3; } @@ -172,7 +212,13 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; // do your while loop here - + do{ + // calling + runningScore +=currentScore; + currentScore = gameNextScore(); + w = w + 1; + // each time through the inner loop + } while (runningScore < highestScore); // calling w = w + 1; // each time through the inner loop @@ -189,9 +235,16 @@ public int checkServerStatus() { String adminPhoneNumber = "+1 202 456 1111"; - // calling - w = w + 1; - // each time through the inner loop + while(serverIsRunning() == true){ + waitFor(5); + w = w + 1; + // each time through the inner loop + } + + if(serverIsRunning() == false){ + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart(); + } return w; } @@ -201,11 +254,12 @@ public int checkServerStatus() { // and if it is, add 7 to “i” public int loop50by7() { int w = 0; - - - // calling + int i = 7; + + while(i < 50){ + i +=7; w = w + 1; - // each time through the inner loop + } return w; } @@ -220,13 +274,17 @@ public int foo() { int sumOfThrees = 0; // this is a so called Enhanced for loop - for (int index : threes_array) { - sumOfThrees = sumOfThrees + threes_array[index]; - // calling + for (int index : threes_array){ + int next = threes_array[w]; + sumOfThrees += next; w = w + 1; - // each time through the inner loop + System.out.println(index); + } - System.out.print("The Sum is "); + // calling + + // each time through the inner loop + System.out.println("The Sum is "); System.out.println(sumOfThrees); return w; @@ -239,10 +297,11 @@ public int rewriteFooAsFor() { int w = 0; int sumOfThrees = 0; - - // calling - w = w + 1; - // each time through the inner loop + for(int i = 0; i < threes_array.length; i++){ + sumOfThrees += threes_array[i]; + w = w + 1; + } + System.out.print("The Sum is "); System.out.println(sumOfThrees); @@ -257,9 +316,10 @@ public int rewriteFooAsWhile() { int sumOfThrees = 0; - // calling - w = w + 1; - // each time through the inner loop + while( w < threes_array.length){ + sumOfThrees += threes_array[w]; + w = w + 1; + } System.out.print("The Sum is "); System.out.println(sumOfThrees); @@ -277,13 +337,16 @@ public int rewriteFooAsWhile() { public int manageYardAndJunior() { int w = 0; boolean onTime = true; - - // ADD YOUR CODE here. - - // be sure to call - w = w + 1; - // each time inside the loop + boolean yardNeedsMowed = true; + while(isSummer()){ + if(yardNeedsMowed == true){ + yellAtJuniorToMowLawn(); + w = w + 1; + isSummer(); + } + } + return w; } @@ -295,12 +358,12 @@ public int manageYardAndJunior() { public int tallyVote1() { int w = 0; int numberOfVotes = voteTallies.length; - - - // calling - w = w + 1; - // each time through the inner loop + for(int i = 0; i < voteTallies.length; i++){ + System.out.println(voteTallies[i]); + w = w + 1; + } + return w; } @@ -310,11 +373,13 @@ public int tallyVote1() { public int tallyVote2() { int w = 0; int numberOfVotes = voteTallies.length; + int idx = 0; - - // calling - w = w + 1; - // each time through the inner loop + while(idx < voteTallies.length){ + System.out.println(voteTallies[idx]); + w = w + 1; + idx++; + } return w; } @@ -389,7 +454,7 @@ private boolean isSummer() { private void sendEmergencyText(String mesg, String phone) { } - private void tryServerRestart(String mesg, String phone) { + private void tryServerRestart() { } int serverStatus = 5; diff --git a/WriteLoopsTest.java b/WriteLoopsTest.java index b836122..b8305f0 100644 --- a/WriteLoopsTest.java +++ b/WriteLoopsTest.java @@ -124,6 +124,58 @@ public void TestCheckServer() WriteLoops writeLoo1 = new WriteLoops(); assertEquals(3, writeLoo1.checkServerStatus()); } + + @Test + public void Testloop50by7() + { + WriteLoops writeLoo1 = new WriteLoops(); + assertEquals(7, writeLoo1.loop50by7()); + } + + @Test + public void Testfoo() + { + int expected = 7; + WriteLoops writeLoo1 = new WriteLoops(); + assertEquals(expected, writeLoo1.foo()); + } + + @Test + public void TestrewriteFooAsFor() + { + int expected = 7; + WriteLoops writeLoo1 = new WriteLoops(); + assertEquals(expected, writeLoo1.rewriteFooAsFor()); + } + + @Test + public void TestrewriteFooAsWhile() + { + int expected = 7; + WriteLoops writeLoo1 = new WriteLoops(); + assertEquals(expected, writeLoo1.rewriteFooAsWhile()); + } + + @Test + public void TestmanageYardAndJunior() + { + WriteLoops writeLoo1 = new WriteLoops(); + assertEquals(0, writeLoo1.manageYardAndJunior()); + } + + @Test + public void TesttallyVote1() + { + WriteLoops writeLoo1 = new WriteLoops(); + assertEquals(13, writeLoo1.tallyVote1()); + } + + @Test + public void TesttallyVote2() + { + WriteLoops writeLoo1 = new WriteLoops(); + assertEquals(13, writeLoo1.tallyVote2()); + } } From 6492f202e76fd92e193d6b2a51ad2b41fb765157 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Mon, 21 Oct 2019 08:35:56 -0400 Subject: [PATCH 4/4] update --- package.bluej | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/package.bluej b/package.bluej index 6c50f1a..e04a489 100644 --- a/package.bluej +++ b/package.bluej @@ -1,26 +1,14 @@ #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=1080 -editor.fx.0.width=954 -editor.fx.0.x=-361 -editor.fx.0.y=-1080 -editor.fx.1.height=1080 -editor.fx.1.width=954 -editor.fx.1.x=-361 -editor.fx.1.y=-1080 -editor.fx.2.height=1080 -editor.fx.2.width=954 -editor.fx.2.x=605 -editor.fx.2.y=-1080 -editor.fx.3.height=1080 -editor.fx.3.width=954 -editor.fx.3.x=605 -editor.fx.3.y=-1080 +editor.fx.0.height=722 +editor.fx.0.width=800 +editor.fx.0.x=320 +editor.fx.0.y=54 objectbench.height=113 objectbench.width=462 package.divider.horizontal=0.6