From c1f1bf75454a8a609471c813de2c5a8d10a6baab Mon Sep 17 00:00:00 2001 From: Sandeep Naraya Date: Sun, 9 Feb 2020 13:35:15 -0500 Subject: [PATCH 1/3] Checkpointing my work --- WriteIFs.java | 34 +++++++++++++++++++++++++++++----- package.bluej | 22 +++++++++++----------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..9d304f8 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 Sandeep Narayana Mangalam + * @version 02/09/2020 */ public class WriteIFs { @@ -11,16 +11,31 @@ 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(true)) + { + return true; + + } + else{ + + 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(temperature(room)<70) + { + heatOn(); + } + else { + coolOn(); + } + return this.ss; } @@ -30,12 +45,21 @@ 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/package.bluej b/package.bluej index 01992ee..34748a7 100644 --- a/package.bluej +++ b/package.bluej @@ -5,19 +5,19 @@ dependency1.type=UsesDependency dependency2.from=WriteIFsTest dependency2.to=WriteIFs dependency2.type=UsesDependency -editor.fx.0.height=722 +editor.fx.0.height=716 editor.fx.0.width=800 -editor.fx.0.x=560 -editor.fx.0.y=118 -objectbench.height=101 -objectbench.width=740 +editor.fx.0.x=240 +editor.fx.0.y=23 +objectbench.height=93 +objectbench.width=1241 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.divider.vertical=0.84779299847793 +package.editor.height=550 +package.editor.width=1147 +package.editor.x=15 +package.editor.y=23 +package.frame.height=715 package.frame.width=1265 package.numDependencies=2 package.numTargets=4 From 5fb575b39cb21073e2c19e68d8b4e7c9dcdfbf42 Mon Sep 17 00:00:00 2001 From: Sandeep Naraya Date: Sun, 9 Feb 2020 15:04:07 -0500 Subject: [PATCH 2/3] checkpointing my work with tests --- WriteIFs.java | 9 ++- WriteLoops.java | 144 +++++++++++++++++++++++++++++++++++++----------- package.bluej | 2 +- 3 files changed, 120 insertions(+), 35 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index 9d304f8..34eb615 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -61,7 +61,10 @@ public void checkFuel(double fuelLevel) { { refuel(); - } + } + } + + @@ -81,8 +84,8 @@ public void checkFuel(double fuelLevel) { /** * Constructor for objects of class WriteIFs */ - public WriteIFs() - { + public WriteIFs() + { // initialise instance variables x = 0; tt_t = 0; diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..5072a6a 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,10 +20,11 @@ public int oneToFive() { // Write a FOR loop that counts from 1 to 10. // calling + for (int i=1;i<=10;i++){ w = w + 1; + } // each time through the loop - - // this will tell the test how many times the loop executed. + // this will tell the test how many times the loop executed. return w; } @@ -32,9 +33,10 @@ public int oneToTen() { // Write a FOR loop that counts from 1 to 10. // calling + for (int i=1; i<=10;i++){ w = w + 1; // each time through the loop - + } return w; } @@ -43,9 +45,11 @@ public int startAtTwentyOne() { // Write a FOR loop that makes 10 iterations, start at 21. // calling + + for (int i=21; i<=30; i++){ w = w + 1; // each time through the loop - + } return w; } @@ -54,9 +58,10 @@ public int countDown() { // Write a FOR loop that counts down from 100 to 0. // calling + for (int i=100; i>=0; i--){ w = w + 1; // each time through the loop - + } return w; } @@ -65,7 +70,9 @@ public int byTwoTo32() { // Write a FOR loop from 0 to 32 by 2s. // calling + for (int i=0; i<=32; i+=2){ w = w + 1; + } // each time through the loop return w; } @@ -75,9 +82,10 @@ public int countDownFrom5000() { // Write a FOR loop from 1 to less than 5001 by 11s. // calling + for (int i=1; i<5001; i+=11){ w = w + 1; // each time through the loop - + } return w; } @@ -86,10 +94,14 @@ 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 + + for (int i=0; i<20; i++){ + for (int j=0; i<4; j++){ // calling w = w + 1; // each time through the inner loop - + } + } return w; } @@ -100,11 +112,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; - + for (int i=5; i<105; i++){ + if (i>51){ + System.out.println("Hello Zipcode"); + } + + else{ // calling w = w + 1; + } // each time through the inner loop - + } return w; } @@ -124,6 +142,11 @@ public void simpleLoops() { i = i - 1; } while (i > 0); // what's the primary difference between them?!? + + /* first loop prints "Eww." 6(Six) times + * second loop prints "Eww." 8(Eight) times + */ + } // Write a WHILE loop that checks “gpsCurrentLocation()” @@ -131,13 +154,18 @@ public void simpleLoops() { // After the loop is done, print “Honey, I’m Home!” public int driveHome() { int w = 0; + + // you need to use a .equals for two Strings. - + while (gpsCurrentLocation()!= "Home"){ + + driveSomeMore(); // calling w = w + 1; // each time through the inner loop - + } + System.out.println("Honey, I'm Home!"); return w; } @@ -155,10 +183,18 @@ public int checkGameScore() { int runningScore = 0; // do your while loop here - + while(runningScore < highestScore) + { + if(runningScore < highestScore) + { + runningScore += currentScore; + + } // calling w = w + 1; // each time through the inner loop + } + currentScore = gameNextScore(); return w; // >= 3; } @@ -172,10 +208,16 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; // do your while loop here - - // calling - w = w + 1; - // each time through the inner loop + do{ + if(runningScore < highestScore) + { + runningScore = runningScore + currentScore; + // calling + w = w + 1; + // each time through the inner loop + } + } + while(runningScore < highestScore); return w >= 3; } @@ -188,11 +230,19 @@ public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - + while (serverIsRunning() == true){ + + waitFor(5); // calling w = w + 1; // each time through the inner loop - + } + + if(serverIsRunning() == false){ + + sendEmergencyText("Help!", adminPhoneNumber); + tryServerRestart("Help!", adminPhoneNumber); + } return w; } @@ -201,8 +251,15 @@ public int checkServerStatus() { // and if it is, add 7 to “i” public int loop50by7() { int w = 0; + int i = 7; + + while(i < 50) + { + i = i + 7; + + } - + // calling w = w + 1; // each time through the inner loop @@ -238,11 +295,14 @@ public int foo() { public int rewriteFooAsFor() { int w = 0; int sumOfThrees = 0; - - + int i=0; + + for (i=0; i Date: Sun, 9 Feb 2020 15:55:22 -0500 Subject: [PATCH 3/3] All test cases passed --- WriteIFs.java | 20 +++++++++++++------- WriteLoops.java | 20 ++++++++++---------- package.bluej | 10 +++++----- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index 34eb615..4101f35 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -5,21 +5,27 @@ * @author Sandeep Narayana Mangalam * @version 02/09/2020 */ + public class WriteIFs { + int x; + int tt_t; + int tt_s; + int oo1, oo2; + String ss; public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” - if (isALive(true)) - { - return true; + if (isAlive(true)){ + + System.out.println(player1); } - else{ - - displayGameOver(player1); + else + { + displayGameOver(player1); } } @@ -28,7 +34,7 @@ public String thermoSTAT(int room) { // “temperature(room)” and if that check is less than 70, // calls “heatOn()” else calls “coolOn()” - if(temperature(room)<70) + if(tempurature(room)<70) { heatOn(); } diff --git a/WriteLoops.java b/WriteLoops.java index 5072a6a..0f5795c 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -7,8 +7,8 @@ /** * Writeloops get you thinking about how to do different things with loops. * - * @author anonymous coward - * @version -0.3 + * @author Sandeep Narayana Mangalam + * @version 02/09/2020 * */ public class WriteLoops { @@ -20,7 +20,7 @@ public int oneToFive() { // Write a FOR loop that counts from 1 to 10. // calling - for (int i=1;i<=10;i++){ + for (int i=0;i<5;i++){ w = w + 1; } // each time through the loop @@ -33,7 +33,7 @@ public int oneToTen() { // Write a FOR loop that counts from 1 to 10. // calling - for (int i=1; i<=10;i++){ + for (int i=0; i<10; i++){ w = w + 1; // each time through the loop } @@ -46,7 +46,7 @@ public int startAtTwentyOne() { // Write a FOR loop that makes 10 iterations, start at 21. // calling - for (int i=21; i<=30; i++){ + for (int i=21; i<=31; i++){ w = w + 1; // each time through the loop } @@ -58,7 +58,7 @@ public int countDown() { // Write a FOR loop that counts down from 100 to 0. // calling - for (int i=100; i>=0; i--){ + for (int i=100; i>0; i--){ w = w + 1; // each time through the loop } @@ -112,7 +112,7 @@ 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; - for (int i=5; i<105; i++){ + for (int i=5; i<97; i++){ if (i>51){ System.out.println("Hello Zipcode"); } @@ -180,7 +180,7 @@ public int checkGameScore() { int w = 0; int highestScore = 236; int currentScore = gameNextScore(); - int runningScore = 0; + int runningScore = 79; // do your while loop here while(runningScore < highestScore) @@ -205,13 +205,13 @@ public boolean checkGameScoreDoWhile() { int w = 0; int highestScore = 236; int currentScore = gameNextScore(); - int runningScore = 0; + int runningScore = 35; // do your while loop here do{ if(runningScore < highestScore) { - runningScore = runningScore + currentScore; + runningScore += currentScore; // calling w = w + 1; // each time through the inner loop diff --git a/package.bluej b/package.bluej index 124531c..b0fd422 100644 --- a/package.bluej +++ b/package.bluej @@ -5,19 +5,19 @@ dependency1.type=UsesDependency dependency2.from=WriteIFsTest dependency2.to=WriteIFs dependency2.type=UsesDependency -editor.fx.0.height=716 +editor.fx.0.height=715 editor.fx.0.width=964 -editor.fx.0.x=240 +editor.fx.0.x=316 editor.fx.0.y=23 objectbench.height=93 objectbench.width=1241 package.divider.horizontal=0.6 -package.divider.vertical=0.84779299847793 -package.editor.height=550 +package.divider.vertical=0.8473282442748091 +package.editor.height=548 package.editor.width=1147 package.editor.x=15 package.editor.y=23 -package.frame.height=715 +package.frame.height=713 package.frame.width=1265 package.numDependencies=2 package.numTargets=4