diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..784affc 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -1,16 +1,28 @@ +import javax.swing.JLayer; /** * Write a description of class WriteIFs here. * - * @author (your name) - * @version (a version number or a date) + * @author dipinti + * @version 06/30/2021 */ public class WriteIFs { + String ss; + int tt_s; + int x; + int tt_t; + int oo1; + int oo2; + public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” + if(isAlive(player1)){ + return; + } + displayGameOver(player1); } @@ -18,9 +30,10 @@ 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(room<70){ + heatOn(); + } + else coolOn(); return this.ss; } @@ -30,13 +43,16 @@ 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();} } diff --git a/WriteIFsTest.java b/WriteIFsTest.java index 8fc6d94..7cdb9bf 100644 --- a/WriteIFsTest.java +++ b/WriteIFsTest.java @@ -1,5 +1,3 @@ - - import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; @@ -9,8 +7,8 @@ * The test class WriteIFsTest. * * @author kyounger - * @version 1.3 - */ + * @version 1.2 + * */ public class WriteIFsTest { private static final double _0_5 = 0.5; diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..6e9bbfc 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 dipinti + * @version 06/30/2021 * */ public class WriteLoops { @@ -17,78 +17,119 @@ public class WriteLoops { public int oneToFive() { int w = 0; + int sum=0; // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + // w = w + 1; // each time through the loop // this will tell the test how many times the loop executed. + for(int i=0;i<5;i++){ + sum+=i; + w+=1; + } return w; } public int oneToTen() { int w = 0; + int sum=0; // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + //w = w + 1; // each time through the loop + for(int i=0;i<10;i++){ + sum+=i; + w+=1; + } return w; } public int startAtTwentyOne() { int w = 0; + int sum=0; // Write a FOR loop that makes 10 iterations, start at 21. // calling - w = w + 1; + //w = w + 1; // each time through the loop + for(int i=21;i<32;i++){ + sum+=i; + w+=1; + } return w; } public int countDown() { int w = 0; + int sum=0; // Write a FOR loop that counts down from 100 to 0. // calling - w = w + 1; + //w = w + 1; // each time through the loop + for(int i=100;i>0;i--){ + sum+=i; + w+=1; + } return w; } public int byTwoTo32() { int w = 0; + int sum=0; + int step=2; // Write a FOR loop from 0 to 32 by 2s. // calling - w = w + 1; + //w = w + 1; // each time through the loop + for(int i=0;i<33;i++){ + sum+=i; + i++; + w+=1; + } return w; } public int countDownFrom5000() { int w = 0; + int sum=0; + int step=11; // Write a FOR loop from 1 to less than 5001 by 11s. // calling - w = w + 1; + //w = w + 1; // each time through the loop + for(int i=1;i<5001;i++){ + sum+=i; + i+=10; + w+=1; + } return w; } public int nestedFors() { int w = 0; + int sum=0; // 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; + // w = w + 1; // each time through the inner loop + for(int i=0;i<20;i++){ + for(int j=0;j<5;j++){ + w+=1; + sum+=j; + } + } return w; } @@ -102,8 +143,14 @@ public int helloZipCode() { // prints “Hello Zipcode” instead of the statement w = w + 1; // calling - w = w + 1; + // w = w + 1; // each time through the inner loop + for(int i=5;i<106;i++){ + if(i>51){ + System.out.println("Hello Zipcode"); + } + else w+=1; + } return w; } @@ -124,6 +171,9 @@ public void simpleLoops() { i = i - 1; } while (i > 0); // what's the primary difference between them?!? + //Answer: The while loop always checks for the condition first, before + //entering the loop. WhereAs in do while loop, first the loop is + //executed and then it check for the while condition. } // Write a WHILE loop that checks “gpsCurrentLocation()” @@ -135,10 +185,13 @@ public int driveHome() { // you need to use a .equals for two Strings. // calling - w = w + 1; + // w = w + 1; // each time through the inner loop - - + while(!(gpsCurrentLocation().equals("Home"))){ + driveSomeMore(); + w+=1; + } + System.out.println("Honey, I’m Home!"); return w; } @@ -148,25 +201,28 @@ public int driveHome() { // is less than “highestScore” and if it is, adds “currentScore” to // "runningScore" // and then sets “currentScore” to “gameNextScore()” - public int checkGameScore() { - int w = 0; + public boolean checkGameScore() { + int w = 1; int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0; - // do your while loop here - // calling - w = w + 1; + // w = w + 1; // each time through the inner loop + while(runningScore= 3; + return w>=3; // >= 3; } // 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; @@ -174,8 +230,13 @@ public boolean checkGameScoreDoWhile() { // do your while loop here // calling - w = w + 1; + // w = w + 1; // each time through the inner loop + do{ + runningScore+=currentScore; + currentScore=gameNextScore(); + w+=1; + }while(runningScore= 3; } @@ -187,12 +248,19 @@ public boolean checkGameScoreDoWhile() { public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - - + String message="Help!"; // calling - w = w + 1; + //w = w + 1; // each time through the inner loop - + while(serverIsRunning()){ + waitFor(5); + w++; + } + if(!serverIsRunning()){ + sendEmergencyText(message,adminPhoneNumber); + tryServerRestart(message,adminPhoneNumber); + //w+=1; + } return w; } @@ -201,11 +269,14 @@ public int checkServerStatus() { // and if it is, add 7 to “i” public int loop50by7() { int w = 0; - - + int i=7; // calling - w = w + 1; + // w = w + 1; // each time through the inner loop + while(i<50){ + i+=7; + w+=1; + } return w; } @@ -238,12 +309,13 @@ public int foo() { public int rewriteFooAsFor() { int w = 0; int sumOfThrees = 0; - - // calling - w = w + 1; + // w = w + 1; // each time through the inner loop - + for(int index:threes_array){ + sumOfThrees+=threes_array[index]; + w+=1; + } System.out.print("The Sum is "); System.out.println(sumOfThrees); @@ -255,12 +327,15 @@ public int rewriteFooAsFor() { public int rewriteFooAsWhile() { int w = 0; int sumOfThrees = 0; - - + int index=0; // calling - w = w + 1; + // w = w + 1; // each time through the inner loop - + while(index<7){ + sumOfThrees+=threes_array[index]; + w+=1; + index++; + } System.out.print("The Sum is "); System.out.println(sumOfThrees); @@ -274,15 +349,22 @@ public int rewriteFooAsWhile() { // After loop, call // “sendJuniorBackToSchool()” with an argument that decribes the day junior goes // back. + public int manageYardAndJunior() { int w = 0; boolean onTime = true; - + boolean yardNeedsMowed=true; // ADD YOUR CODE here. - // be sure to call - w = w + 1; + //w = w + 1; // each time inside the loop + while(isSummer()){ + if(yardNeedsMowed){ + yellAtJuniorToMowLawn(); + w+=1; + } + sendJuniorBackToSchool("Monday"); + } return w; } @@ -295,11 +377,13 @@ public int manageYardAndJunior() { public int tallyVote1() { int w = 0; int numberOfVotes = voteTallies.length; - - // calling - w = w + 1; + //w = w + 1; // each time through the inner loop + for(int index=0;index