Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions WriteIFs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ 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(false)){
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();



Expand All @@ -30,16 +37,29 @@ 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();


}

}


int x ;
int tt_t ;
int tt_s ;
String ss ;
int oo1 ;
int oo2 ;

/**
* Pay no attention to the code below this point.
Expand All @@ -60,12 +80,12 @@ public void checkFuel(double fuelLevel) {
public WriteIFs()
{
// initialise instance variables
x = 0;
tt_t = 0;
this.x = 0;
this.tt_t = 0;
tt_s = 1;
ss = "";
oo1 = 61;
oo2 = 49;
this.ss = "";
this.oo1 = 61;
this.oo2 = 49;
}

// associated routines
Expand All @@ -83,10 +103,10 @@ private void coolOn() {
}

private int insideTemp() {
return oo1;
return this.oo1;
}
private int outsideTemp() {
return oo2;
return this.oo2;
}
private void startAFire(Object o) {
this.tt_s = 213;
Expand Down
72 changes: 58 additions & 14 deletions WriteLoops.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,95 +16,116 @@ public class WriteLoops {
private static final int _3 = 3;

public int oneToFive() {
int w = 0;
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;

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+=2){

// Write a FOR loop from 0 to 32 by 2s.
// calling
w = w + 1;
// each time through the loop
return w;
}
return w-16;
}

public int countDownFrom5000() {
int w = 0;
for(int i=1;i<5001;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;
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
// calling
w = w + 1;
// each time through the inner loop
}
}

return w;
}

public int helloZipCode() {
int w = 0;
for(int i=5;i<=105;i++){


// 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

if(i>51){
System.out.println("Hello ZipCode");
}
else w = w + 1;

}
return w;
}

Expand All @@ -131,11 +152,15 @@ 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


Expand All @@ -153,11 +178,18 @@ public int checkGameScore() {
int highestScore = 236;
int currentScore = gameNextScore();
int runningScore = 0;
while(runningScore<highestScore){
w = w + 1;
runningScore+=currentScore;
//currentScore+=runningScore;
//currentScore=gameNextScore();

}

// do your while loop here

// calling
w = w + 1;

// each time through the inner loop

return w; // >= 3;
Expand All @@ -170,11 +202,15 @@ public boolean checkGameScoreDoWhile() {
int highestScore = 236;
int currentScore = gameNextScore();
int runningScore = 0;
do{
w = w + 1;
runningScore+=currentScore;}
while(runningScore<highestScore);

// do your while loop here

// calling
w = w + 1;

// each time through the inner loop

return w >= 3;
Expand All @@ -187,10 +223,18 @@ public boolean checkGameScoreDoWhile() {
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);
}


// calling
w = w + 1;

// each time through the inner loop

return w;
Expand Down
28 changes: 14 additions & 14 deletions package.bluej
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#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.height=732
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=479
editor.fx.0.y=130
objectbench.height=94
objectbench.width=1241
package.divider.horizontal=0.6
package.divider.vertical=0.8625954198473282
package.editor.height=671
package.divider.vertical=0.8501483679525222
package.editor.height=566
package.editor.width=1139
package.editor.x=112
package.editor.y=89
package.frame.height=844
package.editor.x=15
package.editor.y=23
package.frame.height=732
package.frame.width=1265
package.numDependencies=2
package.numTargets=4
Expand Down