diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..4101f35 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -2,25 +2,46 @@ /** * Write a description of class WriteIFs here. * - * @author (your name) - * @version (a version number or a date) + * @author Sandeep Narayana Mangalam + * @version 02/09/2020 */ + public class WriteIFs { + int x; + int tt_t; + int tt_s; + int oo1, oo2; + String ss; public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - + + if (isAlive(true)){ + + System.out.println(player1); + + } + else + { + 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,14 +51,26 @@ 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(); + + } + } + - } @@ -57,8 +90,8 @@ public void checkFuel(double fuelLevel) { /** * Constructor for objects of class WriteIFs */ - public WriteIFs() - { + public WriteIFs() + { // initialise instance variables x = 0; tt_t = 0; diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..0f5795c 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; @@ -7,8 +7,8 @@ /** * Writeloops get you thinking about how to do different things with loops. * - * @author anonymous coward - * @version -0.3 + * @author Sandeep Narayana Mangalam + * @version 02/09/2020 * */ public class WriteLoops { @@ -20,10 +20,11 @@ public int oneToFive() { // 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. + // this will tell the test how many times the loop executed. return w; } @@ -32,9 +33,10 @@ 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,9 +45,11 @@ 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,9 +58,10 @@ public int countDown() { // Write a FOR loop that counts down from 100 to 0. // calling + for (int i=100; i>0; i--){ w = w + 1; // each time through the loop - + } return w; } @@ -65,7 +70,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,9 +82,10 @@ 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; } @@ -86,10 +94,14 @@ 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 + + for (int i=0; i<20; i++){ + for (int j=0; i<4; j++){ // calling w = w + 1; // each time through the inner loop - + } + } return w; } @@ -100,11 +112,17 @@ 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<97; i++){ + if (i>51){ + System.out.println("Hello Zipcode"); + } + + else{ // calling w = w + 1; + } // each time through the inner loop - + } return w; } @@ -124,6 +142,11 @@ public void simpleLoops() { i = i - 1; } while (i > 0); // what's the primary difference between them?!? + + /* first loop prints "Eww." 6(Six) times + * second loop prints "Eww." 8(Eight) times + */ + } // Write a WHILE loop that checks “gpsCurrentLocation()” @@ -131,13 +154,18 @@ 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()!= "Home"){ + + driveSomeMore(); // calling w = w + 1; // each time through the inner loop - + } + System.out.println("Honey, I'm Home!"); return w; } @@ -152,13 +180,21 @@ public int checkGameScore() { int w = 0; int highestScore = 236; int currentScore = gameNextScore(); - int runningScore = 0; + int runningScore = 79; // do your while loop here - + while(runningScore < highestScore) + { + if(runningScore < highestScore) + { + runningScore += currentScore; + + } // calling w = w + 1; // each time through the inner loop + } + currentScore = gameNextScore(); return w; // >= 3; } @@ -169,13 +205,19 @@ public boolean checkGameScoreDoWhile() { int w = 0; int highestScore = 236; int currentScore = gameNextScore(); - int runningScore = 0; + int runningScore = 35; // do your while loop here - - // calling - w = w + 1; - // each time through the inner loop + do{ + if(runningScore < highestScore) + { + runningScore += currentScore; + // calling + w = w + 1; + // each time through the inner loop + } + } + while(runningScore < highestScore); return w >= 3; } @@ -188,11 +230,19 @@ public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - + while (serverIsRunning() == true){ + + waitFor(5); // calling w = w + 1; // each time through the inner loop - + } + + if(serverIsRunning() == false){ + + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Help!", adminPhoneNumber); + } return w; } @@ -201,8 +251,15 @@ 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; + + } - + // calling w = w + 1; // each time through the inner loop @@ -238,11 +295,14 @@ public int foo() { public int rewriteFooAsFor() { int w = 0; int sumOfThrees = 0; - - + int i=0; + + for (i=0; i