diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..56f7031 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -11,14 +11,19 @@ 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); } - +} 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 +35,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<.08){refuel(); + } } @@ -46,7 +55,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..3d4c146 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 = 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 +32,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 +46,10 @@ 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; @@ -51,23 +57,26 @@ public int startAtTwentyOne() { public int countDown() { int w = 0; - + + for(int i = 99; i >= 0; i--){ // Write a FOR loop that counts down from 100 to 0. // calling w = w + 1; // each time through the loop - + } return w; } public int byTwoTo32() { - int w = 0; - + int w = -16; // Write a FOR loop from 0 to 32 by 2s. // calling + for(int i = 1; i <= 32; i+=2) { w = w + 1; + } // each time through the loop return w; + } public int countDownFrom5000() { @@ -75,9 +84,10 @@ public int countDownFrom5000() { // Write a FOR loop from 1 to less than 5001 by 11s. // calling + for(int i = 5001; i >= 1; i = 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 - 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; @@ -100,9 +114,14 @@ public int helloZipCode() { // statement inside the loop that checks the // loop index counter and if it’s greater than 51, // prints “Hello Zipcode” instead of the statement w = w + 1; - + for(int i = 5; i <= 105; i++){ // calling - w = w + 1; + if(i > 51) {System.out.println("Hello Zipcode"); + + }else{ + w = w + 1; + } + } // each time through the inner loop return w; @@ -131,11 +150,15 @@ public void simpleLoops() { // After the loop is done, print “Honey, I’m Home!” public int driveHome() { int w = 0; - + // you need to use a .equals for two Strings. - + while(!gpsCurrentLocation().equals("Home")){ + driveSomeMore(); + w = w + 1; + } + System.out.println("Honey, I'm Home'"); // calling - w = w + 1; + // each time through the inner loop @@ -153,11 +176,23 @@ public int checkGameScore() { int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0; + + while(runningScore < highestScore || w < 3){ + w = w + 1; + if(runningScore < highestScore){ + runningScore += currentScore; + currentScore = gameNextScore(); + + + } + + } + // do your while loop here // calling - w = w + 1; + // each time through the inner loop return w; // >= 3; @@ -172,9 +207,12 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; // do your while loop here - + do{runningScore += currentScore; + currentScore = gameNextScore(); // calling w = w + 1; + } while (runningScore < highestScore || w < 3); + // each time through the inner loop return w >= 3; @@ -188,21 +226,34 @@ public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - + while(serverIsRunning()==true){ + waitFor(5); + w++; + } + if (serverIsRunning()==false){ + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Help!", adminPhoneNumber); + } // calling - w = w + 1; + + + // each time through the inner loop return w; } + // Declare an “int” i. Set i to 7. // Write a WHILE loop that checks “i” is less than 50, // and if it is, add 7 to “i” public int loop50by7() { int w = 0; - - + int i = 7; + while(i<50){ + i = i + 7; + + } // calling w = w + 1; // each time through the inner loop @@ -238,8 +289,12 @@ 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]; + } + // calling w = w + 1; // each time through the inner loop @@ -256,7 +311,9 @@ public int rewriteFooAsWhile() { int w = 0; int sumOfThrees = 0; - + while(w