diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..359c851 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -2,25 +2,36 @@ /** * Write a description of class WriteIFs here. * - * @author (your name) - * @version (a version number or a date) + * @author Nathan + * @version 6/29/21 */ public class WriteIFs { - + int x = 0; + int tt_t = 0; + int tt_s = 1; + String ss = ""; + int oo1 = 61; + int oo2 = 49; + + public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - + if (!isAlive(player1)) { + 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 +41,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 < 0.08) { + refuel(); + } } @@ -60,12 +75,12 @@ public void checkFuel(double fuelLevel) { public WriteIFs() { // initialise instance variables - x = 0; - tt_t = 0; - tt_s = 1; - ss = ""; - oo1 = 61; - oo2 = 49; + int x = 0; + int tt_t = 0; + int tt_s = 1; + String ss = ""; + int oo1 = 61; + int oo2 = 49; } // associated routines diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..cd0af50 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,22 +17,25 @@ public class WriteLoops { public int oneToFive() { int w = 0; - + for (int i=0; i < 5; i++) { + w += 1; + } // 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. return w; } public int oneToTen() { int w = 0; - + for (int i = 0; i < 10; i++) { + w += 1; + } // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; + // w = w + 1; // each time through the loop return w; @@ -40,10 +43,12 @@ public int oneToTen() { public int startAtTwentyOne() { int w = 0; - + for (int i= 21; i < 32; i++) { + w += 1; + } // Write a FOR loop that makes 10 iterations, start at 21. // calling - w = w + 1; + // w = w + 1; // each time through the loop return w; @@ -51,31 +56,36 @@ public int startAtTwentyOne() { public int countDown() { int w = 0; - + for (int i = 100; i > 0; i--) { + w += 1; + } // Write a FOR loop that counts down from 100 to 0. // calling - w = w + 1; + // w = w + 1; // each time through the loop - return w; } public int byTwoTo32() { int w = 0; - + for (int i = 0; i <= 32; i += 2) { + w += 1; + } // Write a FOR loop from 0 to 32 by 2s. // calling - w = w + 1; + // w = w + 1; // each time through the loop return w; } public int countDownFrom5000() { int w = 0; - + for (int i = 0; i < 5001; i += 11) { + w += 1; + } // Write a FOR loop from 1 to less than 5001 by 11s. // calling - w = w + 1; + // w = w + 1; // each time through the loop return w; @@ -83,11 +93,15 @@ public int countDownFrom5000() { public int nestedFors() { int w = 0; - + for (int i = 0; i < 20; i++) { + for (int x = 0; x < 5; x++) { + 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; + // w = w + 1; // each time through the inner loop return w; @@ -95,14 +109,20 @@ 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 += 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; + // w = w + 1; // each time through the inner loop return w; @@ -131,15 +151,18 @@ public void simpleLoops() { // After the loop is done, print “Honey, I’m Home!” public int driveHome() { int w = 0; - + while(gpsCurrentLocation() != "Home" ) { + driveSomeMore(); + w += 1; + } + System.out.println("Honey, I'm Home!L"); // you need to use a .equals for two Strings. // calling - w = w + 1; + // w = w + 1; // each time through the inner loop - - return w; + return w; } // Getting harder... @@ -155,11 +178,13 @@ public int checkGameScore() { int runningScore = 0; // do your while loop here - - // calling + while (runningScore < highestScore) { + runningScore += currentScore; + currentScore = gameNextScore(); + // calling w = w + 1; // each time through the inner loop - + } return w; // >= 3; } @@ -172,11 +197,13 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; // do your while loop here - + do { + runningScore += currentScore; + currentScore = gameNextScore(); // calling w = w + 1; // each time through the inner loop - + } while (runningScore > highestScore); return w >= 3; } @@ -187,12 +214,16 @@ public boolean checkGameScoreDoWhile() { public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - - - // calling - w = w + 1; - // each time through the inner loop - + while(serverIsRunning()){ + waitFor(5); + // calling + w = w + 1; + // each time through the inner loop + } + if(!serverIsRunning()) { + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Restart server", "2012031923"); + } return w; } @@ -201,12 +232,13 @@ public int checkServerStatus() { // and if it is, add 7 to “i” public int loop50by7() { int w = 0; - - + int i = 7; + while(i < 50) { // calling w = w + 1; // each time through the inner loop - + i += 7; + } return w; } @@ -238,15 +270,15 @@ 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 - System.out.print("The Sum is "); - System.out.println(sumOfThrees); - + System.out.print("The Sum is "); + System.out.println(sumOfThrees); + } return w; } @@ -255,12 +287,14 @@ public int rewriteFooAsFor() { public int rewriteFooAsWhile() { int w = 0; int sumOfThrees = 0; - - + int i = 0; + while (i < threes_array.length) { + sumOfThrees += threes_array[i]; // calling w = w + 1; // each time through the inner loop - + i++; + } System.out.print("The Sum is "); System.out.println(sumOfThrees); @@ -274,16 +308,21 @@ 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; + while(isSummer()) { // ADD YOUR CODE here. - - // be sure to call + if(yardNeedsMowed) { + yellAtJuniorToMowLawn(); + // be sure to call w = w + 1; // each time inside the loop - + } + } + sendJuniorBackToSchool("Monday"); return w; } @@ -295,12 +334,12 @@ public int manageYardAndJunior() { public int tallyVote1() { int w = 0; int numberOfVotes = voteTallies.length; - - + for (int i = 0; i < voteTallies.length; i++) { + System.out.print(voteTallies[i]); // calling w = w + 1; // each time through the inner loop - + } return w; } @@ -310,12 +349,14 @@ public int tallyVote1() { public int tallyVote2() { int w = 0; int numberOfVotes = voteTallies.length; - - + int idx = 0; + while(idx < voteTallies.length){ + System.out.print(voteTallies[idx]); // calling w = w + 1; + idx++; // each time through the inner loop - + } return w; } diff --git a/WriteLoopsTest.java b/WriteLoopsTest.java index 7c9324e..f2ceacb 100644 --- a/WriteLoopsTest.java +++ b/WriteLoopsTest.java @@ -107,7 +107,7 @@ public void TestDriveHome() public void TestCheckGameScore() { WriteLoops writeLoo1 = new WriteLoops(); - assertEquals(true, writeLoo1.checkGameScore()); + assertEquals(3, writeLoo1.checkGameScore()); } @Test diff --git a/package.bluej b/package.bluej index 01992ee..5164d72 100644 --- a/package.bluej +++ b/package.bluej @@ -1,32 +1,32 @@ #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 -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 +editor.fx.0.height=708 +editor.fx.0.width=708 +editor.fx.0.x=550 +editor.fx.0.y=25 +objectbench.height=82 +objectbench.width=358 +package.divider.horizontal=0.7604166666666666 +package.divider.vertical=0.7601078167115903 +package.editor.height=275 +package.editor.width=383 +package.editor.x=34 +package.editor.y=47 +package.frame.height=435 +package.frame.width=500 package.numDependencies=2 -package.numTargets=4 +package.numTargets=5 package.showExtends=true package.showUses=true project.charset=UTF-8 -readme.height=58 +readme.height=60 readme.name=@README -readme.width=47 +readme.width=48 readme.x=10 readme.y=10 target1.height=110 @@ -34,22 +34,22 @@ target1.name=WriteLoopsTest target1.showInterface=false target1.type=UnitTestTargetJunit4 target1.width=100 -target1.x=170 -target1.y=330 +target1.x=190 +target1.y=100 target2.association=WriteLoopsTest target2.height=110 target2.name=WriteLoops target2.showInterface=false target2.type=ClassTarget target2.width=100 -target2.x=140 -target2.y=360 +target2.x=160 +target2.y=130 target3.height=110 target3.name=WriteIFsTest target3.showInterface=false target3.type=UnitTestTargetJunit4 target3.width=80 -target3.x=180 +target3.x=50 target3.y=100 target4.association=WriteIFsTest target4.height=110 @@ -57,5 +57,11 @@ target4.name=WriteIFs target4.showInterface=false target4.type=ClassTarget target4.width=80 -target4.x=150 +target4.x=20 target4.y=130 +target5.height=70 +target5.name=README.md +target5.type=TextTarget +target5.width=120 +target5.x=70 +target5.y=10