diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..19af84a 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -2,8 +2,8 @@ /** * Write a description of class WriteIFs here. * - * @author (your name) - * @version (a version number or a date) + * @author Maira Botelho + * @version 10.18.2019 */ public class WriteIFs { @@ -11,16 +11,21 @@ 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( room < 70){ + heatOn(); + }else if(room > 70){ + coolOn(); + } - - return this.ss; } @@ -30,12 +35,20 @@ public void fireplaceControl(Object fireplace1) { // AND // “insideTemp()” is less than 62, // calls “startAFire(fireplace1)” + if(outsideTemp() < 50 && insideTemp() < 62){ + startAFire(fireplace1); + }else{ + 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(); + } } @@ -46,7 +59,9 @@ 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..f941d2f 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; @@ -20,7 +20,9 @@ public int oneToFive() { // Write a FOR loop that counts from 1 to 10. // calling + for(int x = 0 ; x < 5; x++) { w = w + 1; + } // each time through the loop // this will tell the test how many times the loop executed. @@ -32,7 +34,9 @@ public int oneToTen() { // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + for(int x = 0 ; x < 10; x++) { + w = w + 1; + } // each time through the loop return w; @@ -43,7 +47,9 @@ public int startAtTwentyOne() { // Write a FOR loop that makes 10 iterations, start at 21. // calling - w = w + 1; + for(int x = 21 ; x > 10; x--) { + w = w + 1; + } // each time through the loop return w; @@ -54,7 +60,9 @@ public int countDown() { // Write a FOR loop that counts down from 100 to 0. // calling - w = w + 1; + for(int x = 100 ; x > 0; x--) { + w = w + 1; + } // each time through the loop return w; @@ -65,7 +73,13 @@ public int byTwoTo32() { // Write a FOR loop from 0 to 32 by 2s. // calling - w = w + 1; + for(int x = 0; x < 32; x++){ + w = w + 1; + x = x + 1; + } + + + // each time through the loop return w; } @@ -75,7 +89,10 @@ public int countDownFrom5000() { // Write a FOR loop from 1 to less than 5001 by 11s. // calling - w = w + 1; + for(int x = 1 ; x < 5001; x++) { + w = w + 1; + x = x + 10; + } // each time through the loop return w; @@ -87,7 +104,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 x = 0; x < 20; x++){ + for(int y = 0; y <= 4; y++){ + w = w + 1; + } + } // each time through the inner loop return w; @@ -100,11 +121,15 @@ 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; - - // calling + for(int x = 5; x < 105; x++){ + + if(x > 51){ + System.out.println("Hello Zipcode"); + }else{ w = w + 1; + } // each time through the inner loop - + } return w; } @@ -124,6 +149,9 @@ public void simpleLoops() { i = i - 1; } while (i > 0); // what's the primary difference between them?!? + /*In the do..while, the loop is executed before checking the condition,so it will be executed at least once even if + * the paramenters are not the same. In the while loop the loop checks for the paramenter, se it needs to be the same + to be executed.*/ } // Write a WHILE loop that checks “gpsCurrentLocation()” @@ -133,11 +161,13 @@ public int driveHome() { int w = 0; // you need to use a .equals for two Strings. - - // calling - w = w + 1; - // each time through the inner loop + while(!gpsCurrentLocation().equals("Home")){ + driveSomeMore(); + w = w + 1; + } + + System.out.println("Honey, I'm Home!"); return w; } @@ -154,13 +184,15 @@ public int checkGameScore() { int currentScore = gameNextScore(); int runningScore = 0; - // do your while loop here - - // calling + while(runningScore < highestScore){ + + runningScore = runningScore + currentScore; + currentScore = gameNextScore(); w = w + 1; // each time through the inner loop - + } return w; // >= 3; + } // Rewrite the previous WHILE loop as a DO..WHILE loop. @@ -170,13 +202,14 @@ public boolean checkGameScoreDoWhile() { int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0; - - // do your while loop here - - // calling + + do{ + + runningScore = runningScore + currentScore; + currentScore = gameNextScore(); w = w + 1; // each time through the inner loop - + }while(runningScore < highestScore); return w >= 3; } @@ -189,10 +222,16 @@ public int checkServerStatus() { String adminPhoneNumber = "+1 202 456 1111"; - // calling - w = w + 1; - // each time through the inner loop + while(serverIsRunning() == true){ + waitFor(5); + w = w + 1; + + } + if(serverIsRunning() == false){ + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Help!", adminPhoneNumber); + } return w; } @@ -201,10 +240,12 @@ public int checkServerStatus() { // and if it is, add 7 to “i” public int loop50by7() { int w = 0; + int i = 7; - - // calling + while (i < 50){ + i = i + 7; w = w + 1; + } // each time through the inner loop return w; @@ -239,9 +280,10 @@ public int rewriteFooAsFor() { int w = 0; int sumOfThrees = 0; - - // calling - w = w + 1; + for(int i = 0; i < threes_array.length; i++){ + sumOfThrees = sumOfThrees + threes_array[i]; + w = w + 1; + } // each time through the inner loop System.out.print("The Sum is "); @@ -255,10 +297,13 @@ public int rewriteFooAsFor() { public int rewriteFooAsWhile() { int w = 0; int sumOfThrees = 0; + int i = 0; - - // calling - w = w + 1; + while( i < threes_array.length){ + + sumOfThrees = sumOfThrees + threes_array[i]; + w = w + 1; + } // each time through the inner loop System.out.print("The Sum is "); @@ -277,11 +322,18 @@ public int rewriteFooAsWhile() { public int manageYardAndJunior() { int w = 0; boolean onTime = true; - - // ADD YOUR CODE here. - - // be sure to call + boolean yardNeedsMowed = true; + + while(isSummer() == true){ + + if(yardNeedsMowed == true){ + yellAtJuniorToMowLawn(); + } + + sendJuniorBackToSchool("Go back to scool!"); + w = w + 1; + } // each time inside the loop return w; @@ -295,10 +347,11 @@ public int manageYardAndJunior() { public int tallyVote1() { int w = 0; int numberOfVotes = voteTallies.length; - - - // calling + + for(int i = 0; i < numberOfVotes; i++){ + System.out.print(voteTallies[i]); w = w + 1; + } // each time through the inner loop return w; @@ -310,10 +363,12 @@ public int tallyVote1() { public int tallyVote2() { int w = 0; int numberOfVotes = voteTallies.length; + int idx = 0; - - // calling + while(idx < numberOfVotes){ + System.out.print(voteTallies[idx]); w = w + 1; + } // each time through the inner loop return w; diff --git a/WriteLoopsTest.java b/WriteLoopsTest.java index b836122..5a8e4bf 100644 --- a/WriteLoopsTest.java +++ b/WriteLoopsTest.java @@ -71,7 +71,7 @@ public void TestCountDown() public void Test2to32() { WriteLoops writeLoo1 = new WriteLoops(); - assertEquals(0, writeLoo1.byTwoTo32()); + assertEquals(16, writeLoo1.byTwoTo32()); } @Test diff --git a/package.bluej b/package.bluej index 01992ee..e340f56 100644 --- a/package.bluej +++ b/package.bluej @@ -1,24 +1,24 @@ #BlueJ package file -dependency1.from=WriteLoopsTest -dependency1.to=WriteLoops +dependency1.from=WriteIFsTest +dependency1.to=WriteIFs dependency1.type=UsesDependency -dependency2.from=WriteIFsTest -dependency2.to=WriteIFs +dependency2.from=WriteLoopsTest +dependency2.to=WriteLoops dependency2.type=UsesDependency -editor.fx.0.height=722 -editor.fx.0.width=800 -editor.fx.0.x=560 -editor.fx.0.y=118 -objectbench.height=101 -objectbench.width=740 +editor.fx.0.height=0 +editor.fx.0.width=0 +editor.fx.0.x=0 +editor.fx.0.y=0 +objectbench.height=92 +objectbench.width=493 package.divider.horizontal=0.6 -package.divider.vertical=0.8625954198473282 -package.editor.height=671 -package.editor.width=1139 -package.editor.x=112 -package.editor.y=89 -package.frame.height=844 -package.frame.width=1265 +package.divider.vertical=0.8493150684931506 +package.editor.height=551 +package.editor.width=399 +package.editor.x=0 +package.editor.y=23 +package.frame.height=715 +package.frame.width=517 package.numDependencies=2 package.numTargets=4 package.showExtends=true