From f8acee360294e251589e686ec56e1cc4f0bd2eab Mon Sep 17 00:00:00 2001 From: sitarameez Date: Tue, 29 Jun 2021 10:27:48 -0400 Subject: [PATCH 1/4] updated code in writeifs but associated routines throw errors please help --- WriteIFs.java | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/WriteIFs.java b/WriteIFs.java index c05fcae..72ccbb8 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -11,14 +11,28 @@ public class WriteIFs public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” // and if that’s false, calls “displayGameOver(player1)” + //String display =""; + if(isAlive(player1)==true){ + System.out.println("Player is alive"); + } + 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(tempurature(room)<70){ + heatOn(); + } + else + { + coolOn(); + } return this.ss; @@ -30,12 +44,18 @@ 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,18 +80,21 @@ public void checkFuel(double fuelLevel) { public WriteIFs() { // initialise instance variables - x = 0; - tt_t = 0; - tt_s = 1; - ss = ""; - oo1 = 61; - oo2 = 49; - } + int tt_s = 1; + String ss = ""; + int x = 0; + int tt_t = 0; + + int oo1 = 61; + int oo2 = 49; + +} // associated routines public boolean isAlive(boolean p) { return !p; } + private int tempurature(int t) { return t+2; } @@ -79,7 +102,7 @@ private void heatOn() { this.ss = "heating"; } private void coolOn() { - this.ss = "cooling"; + ss = "cooling"; } private int insideTemp() { @@ -98,3 +121,4 @@ private void displayGameOver(boolean b) { this.ss = "Game Over!"; } } + From a4c78aa2966f75dec76386a085cc0361fe2ae454 Mon Sep 17 00:00:00 2001 From: sitarameez Date: Tue, 29 Jun 2021 10:35:49 -0400 Subject: [PATCH 2/4] figured it out writeifs complete --- WriteIFs.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WriteIFs.java b/WriteIFs.java index 72ccbb8..d856518 100644 --- a/WriteIFs.java +++ b/WriteIFs.java @@ -7,6 +7,12 @@ */ public class WriteIFs { + int tt_s = 1; + int x = 0; + int tt_t = 0; + String ss = ""; + int oo1 = 61; + int oo2 = 49; public void playerDied(boolean player1) { // Write an IF statement that checks “player1.isAlive()” @@ -102,7 +108,7 @@ private void heatOn() { this.ss = "heating"; } private void coolOn() { - ss = "cooling"; + this.ss = "cooling"; } private int insideTemp() { From c2cfbdd9a702e4e04845eb871a06d77509779a6f Mon Sep 17 00:00:00 2001 From: sitarameez Date: Tue, 29 Jun 2021 21:17:29 -0400 Subject: [PATCH 3/4] updated all except do while --- WriteLoops.java | 94 ++++++++++++++++++++++++++++++++++--------------- package.bluej | 40 ++++++++++++--------- 2 files changed, 88 insertions(+), 46 deletions(-) diff --git a/WriteLoops.java b/WriteLoops.java index d629a54..2bfe8e5 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -1,4 +1,4 @@ -import com.sun.org.apache.xpath.internal.SourceTree; + import java.awt.SystemTray; import java.util.concurrent.ThreadLocalRandom; @@ -17,77 +17,86 @@ public class WriteLoops { public int oneToFive() { int w = 0; - + for(int i=1;i<=5;i++){ + // Write a FOR loop that counts from 1 to 10. // calling 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=1;i<=10;i++){ // 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=21;i<=31;i++){ // 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; - + 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++){ // Write a FOR loop from 0 to 32 by 2s. // calling + w=i/2; w = w + 1; // each time through the loop + } return w; } public int countDownFrom5000() { int w = 0; - + for(int i=1;i<5001;i++){ + w=i/11; // 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; + int w=0; + for(int i=0;i<20;i++){ + for(int j=0;j<=4;j++){ + w = 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; + // each time through the inner loop return w; @@ -95,16 +104,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"); + } // 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; - + else{ // calling w = w + 1; // each time through the inner loop - + } + } return w; } @@ -131,11 +144,14 @@ public void simpleLoops() { // After the loop is done, print “Honey, I’m Home!” public int driveHome() { int w = 0; - + while(!gpsCurrentLocation().equals("Home")){ + driveSomeMore(); + w = w + 1; + } // you need to use a .equals for two Strings. - + System.out.println("Honey, I’m Home!"); // calling - w = w + 1; + // each time through the inner loop @@ -148,19 +164,22 @@ public int driveHome() { // is less than “highestScore” and if it is, adds “currentScore” to // "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 - + while(runningScore= 3; + } + return w >= 3; } // Rewrite the previous WHILE loop as a DO..WHILE loop. @@ -170,14 +189,23 @@ public boolean checkGameScoreDoWhile() { int highestScore = 236; int currentScore = gameNextScore(); int runningScore = 0; - + + do{ + runningScore = currentScore; + currentScore=gameNextScore(); + w = w + 1; + } + while(runningScore= 3; + return w>= 3; } // Write a WHILE loop that checks “serverIsRunning()” and if true @@ -188,9 +216,17 @@ public int checkServerStatus() { int w = 0; String adminPhoneNumber = "+1 202 456 1111"; - + while(serverIsRunning()== true){ + waitFor(5); + w = w + 1; + } + if(serverIsRunning()==false){ + sendEmergencyText("Help!",adminPhoneNumber); + tryServerRestart("Help!",adminPhoneNumber); + + } // calling - w = w + 1; + // each time through the inner loop return w; diff --git a/package.bluej b/package.bluej index 01992ee..15d24e6 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 +editor.fx.0.x=417 +editor.fx.0.y=38 +objectbench.height=95 +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.85 +package.editor.height=571 +package.editor.width=1147 +package.editor.x=15 +package.editor.y=26 +package.frame.height=738 package.frame.width=1265 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 @@ -59,3 +59,9 @@ target4.type=ClassTarget target4.width=80 target4.x=150 target4.y=130 +target5.height=70 +target5.name=README.md +target5.type=TextTarget +target5.width=120 +target5.x=70 +target5.y=10 From f51a51d3f85614c2d5a8f422c7f5592cf503dfcf Mon Sep 17 00:00:00 2001 From: sitarameez Date: Fri, 2 Jul 2021 18:29:57 -0400 Subject: [PATCH 4/4] completed but bluej not working after --- .DS_Store | Bin 0 -> 6148 bytes WriteLoops.java | 4 ++-- package.bluej | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d101ae5ba41e8334dcc6e26f01372fa8f3e1db6c GIT binary patch literal 6148 zcmeHK%T59@6g@>2h(YkNa5+0&k+^m<5-=g^MoDz(0LF+Ih=6f9KVjmp_;q@2+vq$B zXkv^py`=Y)PEYUcnVEJ9Ks9FleV_)Q#3EQM(>YA8OUYTmwp58qj}hSp*Qle5VXn7t z@CtYZ{+a^v?p82HgdXnbKi}UO-{e7iIO=tWqb_^N5^=z?_oj_CU=?R*;Sf!n66?4} zKf`#i;FSGk2MN>h5hjV=uiA^6aIu*jhS{V=kiPw?=W#N#3306Uo0n zYTUEMN^1ta_X>CgyaFEz$odel2!(p(?lbu2{sRUu;lQ=W$?}`@T&^E1C4g~%K!iX literal 0 HcmV?d00001 diff --git a/WriteLoops.java b/WriteLoops.java index 2bfe8e5..8b57d80 100644 --- a/WriteLoops.java +++ b/WriteLoops.java @@ -191,7 +191,7 @@ public boolean checkGameScoreDoWhile() { int runningScore = 0; do{ - runningScore = currentScore; + currentScore = runningScore; currentScore=gameNextScore(); w = w + 1; } @@ -205,7 +205,7 @@ public boolean checkGameScoreDoWhile() { // each time through the inner loop - return w>= 3; + return w>3; } // Write a WHILE loop that checks “serverIsRunning()” and if true diff --git a/package.bluej b/package.bluej index 15d24e6..f3288a2 100644 --- a/package.bluej +++ b/package.bluej @@ -5,19 +5,19 @@ dependency1.type=UsesDependency dependency2.from=WriteLoopsTest dependency2.to=WriteLoops dependency2.type=UsesDependency -editor.fx.0.height=722 -editor.fx.0.width=800 -editor.fx.0.x=417 -editor.fx.0.y=38 -objectbench.height=95 +editor.fx.0.height=727 +editor.fx.0.width=1280 +editor.fx.0.x=0 +editor.fx.0.y=23 +objectbench.height=93 objectbench.width=1241 package.divider.horizontal=0.6 -package.divider.vertical=0.85 -package.editor.height=571 +package.divider.vertical=0.8502994011976048 +package.editor.height=561 package.editor.width=1147 package.editor.x=15 -package.editor.y=26 -package.frame.height=738 +package.editor.y=23 +package.frame.height=726 package.frame.width=1265 package.numDependencies=2 package.numTargets=5