From 7f530ad41ce5a93ecd823f02ab41394803967920 Mon Sep 17 00:00:00 2001 From: Sandy Setiawan Date: Sun, 9 Feb 2020 21:24:29 -0500 Subject: [PATCH] First Saturday Sandy Setiawan --- WriteIFs.java | 33 ++++++++++----- WriteLoops.java | 107 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 103 insertions(+), 37 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..217ead9 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -9,12 +9,23 @@ public class WriteIFs { public void playerDied(boolean player1) { + + if(isAlive(player1) == false) { + displayGameOver(player1); + } + // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - } + public String thermoSTAT(int room) { + if(temperature(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()” @@ -24,8 +35,12 @@ public String thermoSTAT(int room) { return this.ss; } - public void fireplaceControl(Object fireplace1) { - // Write an IF statement that checks + public void fireplaceControl(Object fireplace1) { + if (outsideTemp() < 50 && insideTemp() < 62){ + startAFire(fireplace1); + } + + // Write an IF statement that checks // “outsideTemp()” is less than 50 // AND // “insideTemp()” is less than 62, @@ -34,19 +49,17 @@ 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()” } +} - /** - * Pay no attention to the code below this point. - * - * - * instance variables - * / + int x; int tt_t; int tt_s; @@ -72,7 +85,7 @@ public WriteIFs() public boolean isAlive(boolean p) { return !p; } - private int tempurature(int t) { + private int temperature(int t) { return t+2; } private void heatOn() { diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..4cbfd12 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 i = 1; i <=5; i++){ + 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,12 @@ public int oneToFive() { public int oneToTen() { int w = 0; - + for (int i = 1; i <=10; i++){ + 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 +46,12 @@ public int oneToTen() { public int startAtTwentyOne() { int w = 0; - + for (int i = 21; i <=31; 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 +59,12 @@ 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 +72,23 @@ public int countDown() { public int byTwoTo32() { int w = 0; - + for (int i = 0; i <= 32; i +=2){ + } // 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 +96,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,14 +115,23 @@ public int nestedFors() { public int helloZipCode() { int w = 0; - + for (int i = 5; i < 105; i ++){ + if( i > 51) { + System.out.println("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 // loop index counter and if it’s greater than 51, // prints “Hello Zipcode” instead of the statement w = w + 1; // calling - w = w + 1; + // each time through the inner loop return w; @@ -110,7 +139,6 @@ public int helloZipCode() { public void simpleLoops() { int i = 0; - // sample while loop while (i <= 5) { System.out.println("Eww."); @@ -131,11 +159,19 @@ public void simpleLoops() { // After the loop is done, print “Honey, I’m Home!” public int driveHome() { int w = 0; - + while(!gpsCurrentLocation().equals("Home")){ + driveSomeMore(); + w = w + 1; + } + System.out.println("Honey, I'm Home!"); + + + + // you need to use a .equals for two Strings. // calling - w = w + 1; + // each time through the inner loop @@ -153,15 +189,23 @@ public int checkGameScore() { int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0; + + while(runningScore < highestScore) { + runningScore += currentScore; + w = w + 1; + currentScore = gameNextScore(); + } + return w; +} - // do your while loop here +// do your while loop here // calling - w = w + 1; + // each time through the inner loop - return w; // >= 3; - } + //return w; // >= 3; + // Rewrite the previous WHILE loop as a DO..WHILE loop. // Notice how the “runningScore” variable usage is different. @@ -170,11 +214,16 @@ public boolean checkGameScoreDoWhile() { int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0; - + do { + runningScore += currentScore; + currentScore = gameNextScore(); + w = w + 1; + } + while(runningScore < highestScore); // do your while loop here // calling - w = w + 1; + // each time through the inner loop return w >= 3; @@ -201,10 +250,14 @@ public int checkServerStatus() { // and if it is, add 7 to “i” public int loop50by7() { int w = 0; - + int i = 7; + while (i < 50) { + i = i + 7; + w = w + 1; + } // calling - w = w + 1; + // each time through the inner loop return w;