From bdb2d9c433b4d636dcdb459f8910f5f950737955 Mon Sep 17 00:00:00 2001 From: Zachary Kitto Date: Fri, 2 Jul 2021 14:49:12 -0400 Subject: [PATCH 1/3] Every test passed except HelloZipcode --- WriteIFs.java | 21 +++++++++++++----- WriteLoops.java | 59 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..faf80dc 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -11,14 +11,21 @@ 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 (player1) { + 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 (tempurature(room) < 70) { + heatOn(); + } + else { + coolOn(); + } return this.ss; @@ -30,13 +37,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 < 0.08) { + refuel(); + } } @@ -46,7 +57,7 @@ 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..f1a6007 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; @@ -18,9 +18,9 @@ public class WriteLoops { public int oneToFive() { int w = 0; - // Write a FOR loop that counts from 1 to 10. - // calling + 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 +32,9 @@ public int oneToTen() { // Write a FOR loop that counts from 1 to 10. // calling + for (int i = 0; i < 10; i++) { w = w + 1; + } // each time through the loop return w; @@ -43,7 +45,9 @@ public int startAtTwentyOne() { // Write a FOR loop that makes 10 iterations, start at 21. // calling + for (int i = 21; i <= 31; i++) { w = w + 1; + } // each time through the loop return w; @@ -54,7 +58,9 @@ 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 +71,9 @@ public int byTwoTo32() { // Write a FOR loop from 0 to 32 by 2s. // calling + for (int i = 0; i <= 32; i += 2) { w = w + 1; + } // each time through the loop return w; } @@ -75,7 +83,9 @@ public int countDownFrom5000() { // Write a FOR loop from 1 to less than 5001 by 11s. // calling + for (int i = 1; i < 5001; i += 11) { w = w + 1; + } // each time through the loop return w; @@ -87,7 +97,11 @@ 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 + 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 +116,13 @@ 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"); w = w + 1; + } + + } // each time through the inner loop return w; @@ -135,7 +155,11 @@ public int driveHome() { // you need to use a .equals for two Strings. // calling + while (gpsCurrentLocation().equals("Home") == false) { + driveSomeMore(); w = w + 1; + } + System.out.println("Honey, I'm Home!"); // each time through the inner loop @@ -148,19 +172,21 @@ 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; + w = w + 1; + } // calling - w = w + 1; // each time through the inner loop - return w; // >= 3; + return w >= 3; // >= 3; } // Rewrite the previous WHILE loop as a DO..WHILE loop. @@ -172,9 +198,12 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; // do your while loop here - - // calling + do { w = w + 1; + runningScore += currentScore; + } while (highestScore > runningScore); + //w = w + 1; + // calling // each time through the inner loop return w >= 3; @@ -187,10 +216,16 @@ public boolean checkGameScoreDoWhile() { public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - + while (serverIsRunning() == true) { + waitFor(5); + w = w + 1; + } + if (serverIsRunning() == false) { + sendEmergencyText("Help!", adminPhoneNumber); + } // calling - w = w + 1; + //w = w + 1; // each time through the inner loop return w; From ccd648831dd0251c010115db0ace67a5061382ab Mon Sep 17 00:00:00 2001 From: Zachary Kitto Date: Fri, 2 Jul 2021 15:00:46 -0400 Subject: [PATCH 2/3] Completed loops that don't have tests --- WriteLoops.java | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/WriteLoops.java b/WriteLoops.java index f1a6007..30fdaef 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -236,10 +236,13 @@ public int checkServerStatus() { // and if it is, add 7 to “i” public int loop50by7() { int w = 0; - + int i = 7; + while (i < 50) { + i += 7; + w = w + 1; + } // calling - w = w + 1; // each time through the inner loop return w; @@ -273,10 +276,13 @@ public int foo() { public int rewriteFooAsFor() { int w = 0; int sumOfThrees = 0; - + for (int i = 0; i < threes_array.length; i++) { + sumOfThrees += threes_array[i]; + w = w + 1; + } // calling - w = w + 1; + // each time through the inner loop System.out.print("The Sum is "); @@ -290,10 +296,15 @@ public int rewriteFooAsFor() { public int rewriteFooAsWhile() { int w = 0; int sumOfThrees = 0; - + int i = 0; + while (i < threes_array.length) { + sumOfThrees += threes_array[i]; + i++; + w = w + 1; + } // calling - w = w + 1; + // each time through the inner loop System.out.print("The Sum is "); @@ -312,11 +323,19 @@ public int rewriteFooAsWhile() { public int manageYardAndJunior() { int w = 0; boolean onTime = true; + boolean yardNeedsMowed = true; + while (isSummer()) { + if (yardNeedsMowed) { + yellAtJuniorToMowLawn(); + w = w + 1; + } + } + sendJuniorBackToSchool("During Winter"); // ADD YOUR CODE here. // be sure to call - w = w + 1; + // each time inside the loop return w; @@ -330,10 +349,13 @@ public int manageYardAndJunior() { public int tallyVote1() { int w = 0; int numberOfVotes = voteTallies.length; - + for (String vote : voteTallies) { + System.out.println(vote); + w = w + 1; + } // calling - w = w + 1; + // each time through the inner loop return w; @@ -345,10 +367,15 @@ public int tallyVote1() { public int tallyVote2() { int w = 0; int numberOfVotes = voteTallies.length; - + int i = 0; + while(i < voteTallies.length) { + System.out.println(voteTallies[i]); + i++; + w = w + 1; + } // calling - w = w + 1; + // each time through the inner loop return w; From ada10fb75f6fd42246a0ae62ac13d2c87a310c58 Mon Sep 17 00:00:00 2001 From: Zachary Kitto Date: Fri, 2 Jul 2021 15:06:57 -0400 Subject: [PATCH 3/3] Got the HelloZipcode method to pass --- WriteLoops.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/WriteLoops.java b/WriteLoops.java index 30fdaef..830d81b 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -119,9 +119,13 @@ public int helloZipCode() { 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 @@ -192,7 +196,7 @@ public boolean checkGameScore() { // Rewrite the previous WHILE loop as a DO..WHILE loop. // Notice how the “runningScore” variable usage is different. public boolean checkGameScoreDoWhile() { - int w = 0; + int w = -1; int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0;