From 0acddcf44a44d5f0fb416102b750528fd031c5d0 Mon Sep 17 00:00:00 2001 From: ushanil Date: Mon, 21 Oct 2019 15:08:32 -0400 Subject: [PATCH 1/4] by usha --- WriteLoops.java | 79 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 14 deletions(-) diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..616046a 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,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 = 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,10 @@ 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; @@ -40,10 +46,14 @@ public int oneToTen() { public int startAtTwentyOne() { int w = 0; + // 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,7 +78,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 +91,10 @@ public int countDownFrom5000() { // Write a FOR loop from 1 to less than 5001 by 11s. // calling - w = w + 1; + for ( int i = 5000 ; i>=1 ; i-=11) + { + w = w + 1; + } // each time through the loop return w; @@ -87,14 +106,22 @@ 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; } - public int helloZipCode() { - int w = 0; + public int helloZipCode() + { + // Write a FOR loop that counts from 5 to 105. Put an IF // statement inside the loop that checks the @@ -102,13 +129,26 @@ public int helloZipCode() { // prints “Hello Zipcode” instead of the statement w = w + 1; // calling - w = w + 1; + int w = 0; + for ( int i = 5 ; i<=105 ; i++) + { + if ( i <= 51) + { + //System.out.println("Hello Zipcode"); + w = w+1; + } + else + { + System.out.println("Hello Zipcode"); + } + // each time through the inner loop - + } return w; } - public void simpleLoops() { + public void simpleLoops() + { int i = 0; // sample while loop @@ -188,9 +228,20 @@ public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; + while(serverIsRunning()) + { + waitFor(5); + w = w + 1; + } + + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Help!", adminPhoneNumber); + + + // calling - w = w + 1; + // each time through the inner loop return w; From f83776d2d4fd02a7d117f6c898ed1bd5dfde4df0 Mon Sep 17 00:00:00 2001 From: ushanil Date: Mon, 21 Oct 2019 15:22:12 -0400 Subject: [PATCH 2/4] usha --- WriteLoops.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/WriteLoops.java b/WriteLoops.java index 616046a..fa56951 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -64,7 +64,7 @@ public int countDown() { // Write a FOR loop that counts down from 100 to 0. // calling - for ( int i = 100 ; i>=0 ; i--) + for ( int i = 100 ; i>0 ; i--) { w = w + 1; } @@ -173,11 +173,14 @@ public int driveHome() { int w = 0; // you need to use a .equals for two Strings. - +while(gpsCurrentLocation() != "Home") +{ // calling + driveSomeMore(); w = w + 1; + } // each time through the inner loop - + System.out.println("Honey, I’m Home!"); return w; } @@ -195,11 +198,13 @@ public int checkGameScore() { int runningScore = 0; // do your while loop here - + while(runningScore < highestScore) + { + runningScore = currentScore + runningScore; // calling w = w + 1; // each time through the inner loop - + } return w; // >= 3; } @@ -212,10 +217,14 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; // do your while loop here - + do + { + runningScore = currentScore + runningScore; // calling w = w + 1; // each time through the inner loop + } while(runningScore < highestScore-1) ; + return w >= 3; } From d75585b6622d20db591b04c5a6b055584f2b050d Mon Sep 17 00:00:00 2001 From: ushanil Date: Mon, 21 Oct 2019 16:08:35 -0400 Subject: [PATCH 3/4] added by usha --- WriteIFs.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..99121c9 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -11,6 +11,10 @@ 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) == false) + { + displayGameOver(player1); + } } @@ -19,7 +23,14 @@ public String thermoSTAT(int room) { // “temperature(room)” and if that check is less than 70, // calls “heatOn()” else calls “coolOn()” - + if (room < 70) + { + heatOn(); + } + else + { + coolOn(); + } return this.ss; } @@ -30,6 +41,15 @@ public void fireplaceControl(Object fireplace1) { // AND // “insideTemp()” is less than 62, // calls “startAFire(fireplace1)” + + + { + if (outsideTemp() < 50 && insideTemp() < 62) + { + startAFire(fireplace1); + } + } + } @@ -46,7 +66,7 @@ public void checkFuel(double fuelLevel) { * * * instance variables - * / + **/ int x; int tt_t; int tt_s; From 9c5f2bd9a545bced47ea13d2c10122cbc0781456 Mon Sep 17 00:00:00 2001 From: ushanil Date: Mon, 21 Oct 2019 16:23:42 -0400 Subject: [PATCH 4/4] usha --- WriteIFs.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/WriteIFs.java b/WriteIFs.java index 99121c9..a3e2eba 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -44,7 +44,7 @@ public void fireplaceControl(Object fireplace1) { { - if (outsideTemp() < 50 && insideTemp() < 62) + if (outsideTemp() < 50 || insideTemp() < 62) { startAFire(fireplace1); } @@ -56,6 +56,10 @@ public void fireplaceControl(Object 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(); + } }