diff --git a/FirstSaturday.iml b/FirstSaturday.iml index c02b99a..da9ecc2 100644 --- a/FirstSaturday.iml +++ b/FirstSaturday.iml @@ -1,21 +1,9 @@ - - - + + - + + - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index ab780ca..9b05a7e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ groupId FirstSaturday 1.0-SNAPSHOT + + 11 + 11 + + + + junit + junit + 4.12 + test + + + - \ No newline at end of file diff --git a/src/main/java/WriteIFs.java b/src/main/java/WriteIFs.java index 0b9911a..2e9605c 100644 --- a/src/main/java/WriteIFs.java +++ b/src/main/java/WriteIFs.java @@ -12,6 +12,9 @@ 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); + } } @@ -19,9 +22,12 @@ 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(temperature(room) < 70) { + heatOn(); + } + else{ + coolOn(); + } return this.ss; } @@ -31,12 +37,20 @@ 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(); + } } @@ -73,7 +87,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/src/main/java/WriteLoops.java b/src/main/java/WriteLoops.java index e7b1305..e3c00a9 100644 --- a/src/main/java/WriteLoops.java +++ b/src/main/java/WriteLoops.java @@ -18,9 +18,10 @@ 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. return w; } @@ -30,9 +31,10 @@ public int oneToTen() { // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; - // each time through the loop - + for (int i = 0; i < 10; i++) { + w = w + 1; + // each time through the loop + } return w; } @@ -41,9 +43,10 @@ public int startAtTwentyOne() { // Write a FOR loop that makes 10 iterations, start at 21. // calling - w = w + 1; - // each time through the loop - + for (int i = 21; i < 32; i++) { + w = w + 1; + // each time through the loop + } return w; } @@ -52,28 +55,31 @@ public int countDown() { // Write a FOR loop that counts down from 100 to 0. // calling - w = w + 1; - // each time through the loop - + for (int i = 100; i > 0; i--) { + w = w + 1; + // each time through the loop + } return w; } public int byTwoTo32() { int w = 0; - // Write a FOR loop from 0 to 32 by 2s. // calling - w = w + 1; - // each time through the loop - return w; + for (int i = 0; i < 16; i++) { + w = w + 2; + } + // each time through the loop + return w; } public int countDownFrom5000() { int w = 0; - // Write a FOR loop from 1 to less than 5001 by 11s. // calling - w = w + 1; + for (int i = 455; i > 0; i--) { + w = w + 1; + } // each time through the loop return w; @@ -85,7 +91,13 @@ 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 + for(int i = 0; i<20; i++){ + for(int a = 0; a<=4; a++){ w = w + 1; + } + } + + // each time through the inner loop return w; @@ -98,9 +110,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; + // calling - // calling + for(int i = 5; i <= 105; i++){ + if(i >= 51){ + System.out.println("Hello Zipcode" + " i is "+ i); + } + else{ w = w + 1; + } + } + // each time through the inner loop return w; @@ -129,11 +149,16 @@ public void simpleLoops() { // After the loop is done, print “Honey, I’m Home!” public int driveHome() { int w = 0; + while(gpsCurrentLocation()!="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,12 +178,20 @@ public int checkGameScore() { int runningScore = 0; // do your while loop here - - // calling - w = w + 1; - // each time through the inner loop + while(runningScore < highestScore){ + runningScore += currentScore; + currentScore = gameNextScore(); + w++; + } + return w; + + //w = w + 1; + + // >= 3; + // calling + // each time through the inner loop - return w; // >= 3; + } // Rewrite the previous WHILE loop as a DO..WHILE loop. @@ -183,14 +216,18 @@ public boolean checkGameScoreDoWhile() { // is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)” // and also calls “tryServerRestart()” public int checkServerStatus() { - int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - - + int w = 0; + while(serverIsRunning()){ + waitFor(5); + w++; + } + if(serverIsRunning() == false){ + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Restart the server.",adminPhoneNumber); + } // calling - w = w + 1; // each time through the inner loop - return w; } @@ -198,14 +235,19 @@ public int checkServerStatus() { // Write a WHILE loop that checks “i” is less than 50, // and if it is, add 7 to “i” public int loop50by7() { - int w = 0; + int i = 7; + while(i < 50) { + + i += 7; + // w = w + 1; + } // calling - w = w + 1; + // each time through the inner loop - return w; + return i; } int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 }; diff --git a/src/test/java/WriteIFsTest.java b/src/test/java/WriteIFsTest.java index 4161980..46940e6 100644 --- a/src/test/java/WriteIFsTest.java +++ b/src/test/java/WriteIFsTest.java @@ -1,5 +1,6 @@ package src.test.java; + import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; diff --git a/src/test/java/WriteLoopsTest.java b/src/test/java/WriteLoopsTest.java index 04943ac..a10fa57 100644 --- a/src/test/java/WriteLoopsTest.java +++ b/src/test/java/WriteLoopsTest.java @@ -74,7 +74,7 @@ public void Test2to32() { //error should be 17? WriteLoops writeLoo1 = new WriteLoops(); - assertEquals(17, writeLoo1.byTwoTo32()); // error in source + assertEquals(32, writeLoo1.byTwoTo32()); // error in source } @Test @@ -95,7 +95,7 @@ public void TestNestedFors() public void TestHelloZipCode() { WriteLoops writeLoo1 = new WriteLoops(); - assertEquals(47, writeLoo1.helloZipCode()); + assertEquals(46, writeLoo1.helloZipCode()); } @Test @@ -111,7 +111,7 @@ public void TestDriveHome() public void TestCheckGameScore() { WriteLoops writeLoo1 = new WriteLoops(); - assertEquals(true, writeLoo1.checkGameScore()); + assertEquals(3, writeLoo1.checkGameScore()); } @Test