From 4d7cf0ab2b0d1bc748a15bde816b9c1b3380b271 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 5 Mar 2023 23:42:51 -0500 Subject: [PATCH 1/6] Made updates to First Saturday lab --- FirstSaturday.iml | 20 ++------ pom.xml | 14 +++++- src/main/java/WriteIFs.java | 22 ++++++++- src/main/java/WriteLoops.java | 92 +++++++++++++++++++++-------------- 4 files changed, 93 insertions(+), 55 deletions(-) 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..9009c58 100644 --- a/src/main/java/WriteIFs.java +++ b/src/main/java/WriteIFs.java @@ -10,22 +10,36 @@ public class WriteIFs { public void playerDied(boolean player1) { + + if(isAlive(player1) != true) { + displayGameOver(player1); + } // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” } public String thermoSTAT(int room) { + + if(tempurature(room) < 70) { + heatOn(); + } + else { + coolOn(); + } + // Write an IF statement that checks the // “temperature(room)” and if that check is less than 70, // calls “heatOn()” else calls “coolOn()” - - return this.ss; } public void fireplaceControl(Object fireplace1) { + + if(outsideTemp() < 50 && insideTemp() < 62) { + startAFire(fireplace1); + } // Write an IF statement that checks // “outsideTemp()” is less than 50 // AND @@ -35,6 +49,10 @@ public void fireplaceControl(Object fireplace1) { } public void checkFuel(double fuelLevel) { + + if(fuelLevel < 0.08) { + refuel(); + } // Write an IF statement that checks “fuelLevel” // and if that check is less than 0.08, calls “refuel()” diff --git a/src/main/java/WriteLoops.java b/src/main/java/WriteLoops.java index e7b1305..beefdfc 100644 --- a/src/main/java/WriteLoops.java +++ b/src/main/java/WriteLoops.java @@ -15,11 +15,12 @@ public class WriteLoops { public int oneToFive() { int w = 0; + for(int i = 0; i < 5; i++) { + w = w + 1; - // Write a FOR loop that counts from 1 to 10. + // Write a FOR loop that counts from 1 to 10. // calling - w = w + 1; - // each time through the loop + } // each time through the loop // this will tell the test how many times the loop executed. return w; @@ -27,72 +28,86 @@ public int oneToFive() { public int oneToTen() { int w = 0; + for(int i = 0; i < 10; i++) { - // Write a FOR loop that counts from 1 to 10. - // calling - w = w + 1; - // each time through the loop - + // Write a FOR loop that counts from 1 to 10. + // calling + w = w + 1; + // each time through the loop + } return w; } public int startAtTwentyOne() { int w = 0; + for(int i = 0; i <= 10; i++) { - // Write a FOR loop that makes 10 iterations, start at 21. - // calling - w = w + 1; - // each time through the loop - + // Write a FOR loop that makes 10 iterations, start at 21. + // calling + w = w + 1; + // each time through the loop + } return w; } public int countDown() { int w = 0; - // 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--) { + // Write a FOR loop that counts down from 100 to 0. + // calling + w = w + 1; + // each time through the loop + } return w; } public int byTwoTo32() { int w = 0; + for(int i = 0; i <= 32; i+=2) { - // Write a FOR loop from 0 to 32 by 2s. - // calling - w = w + 1; - // each time through the loop + // Write a FOR loop from 0 to 32 by 2s. + // calling + w = w + 1; + } // each time through the loop return w; } public int countDownFrom5000() { int w = 0; + for(int i = 5001; i > 0; i -= 11) { - // Write a FOR loop from 1 to less than 5001 by 11s. - // calling - w = w + 1; - // each time through the loop - + // Write a FOR loop from 1 to less than 5001 by 11s. + // calling + w = w + 1; + // each time through the loop + } return w; } public int nestedFors() { int w = 0; + for(int i = 0; i <= 20; i++) { + for(int j = 0; j < 4; j++) { - // Write a nested FOR loop(s), where one counts from - // 0 to less than 20 and the inner one counts from 0 to 4 + // 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; - // each time through the inner loop - + } // each time through the inner loop + } return w; } public int helloZipCode() { int w = 0; + for(int i = 5; i <= 105; i++) { + if(w > 51) { + System.out.println("Hello Zipcode"); + } else { + w = w + 1; + } + } // Write a FOR loop that counts from 5 to 105. Put an IF // statement inside the loop that checks the @@ -129,14 +144,17 @@ public void simpleLoops() { // After the loop is done, print “Honey, I’m Home!” public int driveHome() { int w = 0; + while(!gpsCurrentLocation().equals("Home")) { + driveSomeMore(); + - // you need to use a .equals for two Strings. + // you need to use a .equals for two Strings. // calling w = w + 1; // each time through the inner loop - - + } + System.out.println("Honey, I'm Home!"); return w; } @@ -146,6 +164,7 @@ 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; int highestScore = 236; @@ -153,11 +172,12 @@ public int checkGameScore() { int runningScore = 0; // do your while loop here - + + // calling w = w + 1; // each time through the inner loop - + return w; // >= 3; } From 46e56d1272213b695062117417d082696d56fbdd Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 6 Mar 2023 08:23:56 -0500 Subject: [PATCH 2/6] Made updates to First Saturday lab --- src/main/java/WriteLoops.java | 60 ++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/src/main/java/WriteLoops.java b/src/main/java/WriteLoops.java index beefdfc..338346d 100644 --- a/src/main/java/WriteLoops.java +++ b/src/main/java/WriteLoops.java @@ -87,8 +87,8 @@ public int countDownFrom5000() { public int nestedFors() { int w = 0; - for(int i = 0; i <= 20; i++) { - for(int j = 0; j < 4; j++) { + for(int i = 0; i < 20; i++) { + for(int j = 0; j <= 4; j++) { // Write a nested FOR loop(s), where one counts from // 0 to less than 20 and the inner one counts from 0 to 4 @@ -101,21 +101,19 @@ public int nestedFors() { public int helloZipCode() { int w = 0; - for(int i = 5; i <= 105; i++) { - if(w > 51) { + for (int i = 4; i < 105; i++) { + if (i == 51) { System.out.println("Hello Zipcode"); + break; } else { w = 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; // each time through the inner loop return w; @@ -146,15 +144,16 @@ public int driveHome() { int w = 0; while(!gpsCurrentLocation().equals("Home")) { driveSomeMore(); - - + if(gpsCurrentLocation().equals("Home")) { + 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 } - System.out.println("Honey, I'm Home!"); + return w; } @@ -165,20 +164,23 @@ public int driveHome() { // "runningScore" // and then sets “currentScore” to “gameNextScore()” - public int checkGameScore() { + public boolean checkGameScore() { int w = 0; int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0; // do your while loop here - - - // calling + while(runningScore < highestScore) { + runningScore += currentScore; + currentScore = gameNextScore(); w = w + 1; + } + // calling + //w = w + 1; // each time through the inner loop - return w; // >= 3; + return w >= 3; // >= 3; } // Rewrite the previous WHILE loop as a DO..WHILE loop. @@ -190,9 +192,15 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; // do your while loop here + do { + runningScore += currentScore; + currentScore = gameNextScore(); + w = w + 1; + + } while (runningScore < highestScore); // calling - w = w + 1; + //w = w + 1; // each time through the inner loop return w >= 3; @@ -205,8 +213,14 @@ public boolean checkGameScoreDoWhile() { public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - + while(serverIsRunning() == true) { + waitFor(5); + } + if(serverIsRunning() == false) { + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart(); + } // calling w = w + 1; // each time through the inner loop @@ -219,10 +233,14 @@ 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 += 7; w = w + 1; + } + // calling + //w = w + 1; // each time through the inner loop return w; @@ -256,6 +274,10 @@ public int foo() { public int rewriteFooAsFor() { int w = 0; int sumOfThrees = 0; + for(int i = 0; i < threes_array.length; i++) { + + + } // calling From 33221fb711f36e3dcf422d021fd4efe7499e382a Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 6 Mar 2023 08:31:59 -0500 Subject: [PATCH 3/6] Made updates to First Saturday lab --- src/main/java/WriteLoops.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/WriteLoops.java b/src/main/java/WriteLoops.java index 338346d..1185c3e 100644 --- a/src/main/java/WriteLoops.java +++ b/src/main/java/WriteLoops.java @@ -216,13 +216,14 @@ public int checkServerStatus() { while(serverIsRunning() == true) { waitFor(5); + w = w + 1; } if(serverIsRunning() == false) { sendEmergencyText("Help!", adminPhoneNumber); - tryServerRestart(); + tryServerRestart("Help!", adminPhoneNumber); } // calling - w = w + 1; + // each time through the inner loop return w; @@ -275,13 +276,14 @@ public int rewriteFooAsFor() { int w = 0; int sumOfThrees = 0; for(int i = 0; i < threes_array.length; i++) { - + sumOfThrees = sumOfThrees + threes_array[i]; + w = w + 1; } // calling - w = w + 1; + // each time through the inner loop System.out.print("The Sum is "); From 5facfbf04b2a24b4854657cba270ba5534b1a6a7 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 6 Mar 2023 08:47:37 -0500 Subject: [PATCH 4/6] Made updates to First Saturday lab --- src/main/java/WriteLoops.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/WriteLoops.java b/src/main/java/WriteLoops.java index 1185c3e..d08e7a0 100644 --- a/src/main/java/WriteLoops.java +++ b/src/main/java/WriteLoops.java @@ -280,8 +280,6 @@ public int rewriteFooAsFor() { w = w + 1; } - - // calling // each time through the inner loop @@ -297,10 +295,15 @@ public int rewriteFooAsFor() { public int rewriteFooAsWhile() { int w = 0; int sumOfThrees = 0; + int i = 0; + while(i < threes_array.length) { + sumOfThrees = sumOfThrees + threes_array[i]; + w += 1; + } // calling - w = w + 1; + //w = w + 1; // each time through the inner loop System.out.print("The Sum is "); From e78c0000cfdf9f50250f4a9a070484a3bea295db Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 6 Mar 2023 08:52:25 -0500 Subject: [PATCH 5/6] Made updates to First Saturday lab --- src/main/java/WriteLoops.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/WriteLoops.java b/src/main/java/WriteLoops.java index d08e7a0..7b8518f 100644 --- a/src/main/java/WriteLoops.java +++ b/src/main/java/WriteLoops.java @@ -324,9 +324,17 @@ public int manageYardAndJunior() { boolean onTime = true; // ADD YOUR CODE here. + boolean yardsNeedsMowed = true; + while(isSummer()) { + if(yardsNeedsMowed) { + yellAtJuniorToMowLawn(); + } + w = w + 1; + } + sendJuniorBackToSchool("Enjoy your first day of school!"); // be sure to call - w = w + 1; + //w = w + 1; // each time inside the loop return w; From dc25bbf1d08b24fde34cba3f313c22cd02565634 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 6 Mar 2023 08:59:47 -0500 Subject: [PATCH 6/6] Made updates to First Saturday lab --- src/main/java/WriteLoops.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/WriteLoops.java b/src/main/java/WriteLoops.java index 7b8518f..9c39d53 100644 --- a/src/main/java/WriteLoops.java +++ b/src/main/java/WriteLoops.java @@ -348,10 +348,14 @@ public int manageYardAndJunior() { public int tallyVote1() { int w = 0; int numberOfVotes = voteTallies.length; + for(int i =0; i < numberOfVotes; i++) { + System.out.println(numberOfVotes); + w = w + 1; + } // calling - w = w + 1; + //w = w + 1; // each time through the inner loop return w; @@ -363,10 +367,16 @@ public int tallyVote1() { public int tallyVote2() { int w = 0; int numberOfVotes = voteTallies.length; + int idx = 0; + while(idx < numberOfVotes) { + System.out.println(idx); + idx++; + w = w + 1; + } // calling - w = w + 1; + // each time through the inner loop return w;