Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished lab #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions BlueJ.FirstSaturday.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
35 changes: 28 additions & 7 deletions WriteIFs.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,36 @@
* @author (your name)
* @version (a version number or a date)
*/
public class WriteIFs
{

public void playerDied(boolean player1) {
public class WriteIFs {
int tt_s = 1;
int x = 0;
int tt_t = 0;
String ss = "";
int oo1 = 61;
int oo2 = 49;

public boolean playerDied(boolean player1) {
// Write an IF statement that checks “player1.isAlive()”
// and if that’s false, calls “displayGameOver(player1)”

if (isAlive(player1)) {


}
if (!isAlive(player1)) displayGameOver(player1);
return false;

}

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 ((room) < 70) {
heatOn();
} else {
coolOn();
}



return this.ss;
Expand All @@ -30,13 +46,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 < .08) {
refuel();
}
}


Expand Down
107 changes: 79 additions & 28 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 java.awt.SystemTray;
import java.util.concurrent.ThreadLocalRandom;
Expand All @@ -20,19 +20,24 @@ public int oneToFive() {

// Write a FOR loop that counts from 1 to 10.
// calling
w = w + 1;

// each time through the loop

for(int i = 0; i < 5; i++){
w = w + 1;
}
// this will tell the test how many times the loop executed.
return w;
}

public int oneToTen() {
int w = 0;

// Write a FOR loop that counts from 1 to 10.
// calling
w = w + 1;

for(int i = 0; i < 10; i++){
w = w+1;
}
// each time through the loop

return w;
Expand All @@ -43,7 +48,10 @@ public int startAtTwentyOne() {

// Write a FOR loop that makes 10 iterations, start at 21.
// calling
w = w + 1;
for(int i = 0; i< 11; i++) {
w = w + 1;
}

// each time through the loop

return w;
Expand All @@ -54,7 +62,10 @@ public int countDown() {

// Write a FOR loop that counts down from 100 to 0.
// calling
w = w + 1;
for(int i = 100; i > 0; i--) {
w = w + 1;
}

// each time through the loop

return w;
Expand All @@ -65,6 +76,7 @@ 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;
Expand All @@ -75,7 +87,10 @@ public int countDownFrom5000() {

// Write a FOR loop from 1 to less than 5001 by 11s.
// calling
w = w + 1;
for (int i = 1; i < 5001; i += 11){
w = w + 1;
}

// each time through the loop

return w;
Expand All @@ -87,22 +102,32 @@ 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
w = w + 1;
for (int i = 0; i < 20; i++){
for(int j = 0; j <= 4; j++){
w = w + 1;
}

// each time through the inner loop

return w;
}

}
return w;
}
public int helloZipCode() {
int w = 0;

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

for(int i = 5; i < 105; i++) {
if(i > 51)
System.out.println("Hello Zipcode");

else w = w+1;

}
// calling
w = w + 1;

// each time through the inner loop

return w;
Expand Down Expand Up @@ -135,10 +160,11 @@ public int driveHome() {
// you need to use a .equals for two Strings.

// calling
w = w + 1;
while(!gpsCurrentLocation().equals("Home")){
w = w + 1;
driveSomeMore();
}
// each time through the inner loop


return w;
}

Expand All @@ -148,7 +174,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() {
public boolean checkGameScore() {
int w = 0;
int highestScore = 236;
int currentScore = gameNextScore();
Expand All @@ -157,10 +183,19 @@ public int checkGameScore() {
// do your while loop here

// calling
w = w + 1;
while(runningScore < highestScore){



runningScore = currentScore;
currentScore = gameNextScore();
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.
Expand All @@ -172,7 +207,11 @@ public boolean checkGameScoreDoWhile() {
int runningScore = 0;

// do your while loop here

do {
runningScore = runningScore + currentScore;
} while(runningScore < highestScore);


// calling
w = w + 1;
// each time through the inner loop
Expand All @@ -188,10 +227,18 @@ public int checkServerStatus() {
int w = 0;
String adminPhoneNumber = "+1 202 456 1111";


// calling
w = w + 1;
// each time through the inner loop
while(serverIsRunning()==true){
waitFor(5);
w = w + 1;
}

if (serverIsRunning()==false){
sendEmergencyText("Help!", adminPhoneNumber);


}



return w;
}
Expand All @@ -201,7 +248,11 @@ public int checkServerStatus() {
// and if it is, add 7 to “i”
public int loop50by7() {
int w = 0;

int i = 7;

while(i < 50) {
i += 7;
}

// calling
w = w + 1;
Expand All @@ -220,7 +271,7 @@ public int foo() {
int sumOfThrees = 0;

// this is a so called Enhanced for loop
for (int index : threes_array) {
for (int index = 0; index < threes_array.length; index++) {
sumOfThrees = sumOfThrees + threes_array[index];
// calling
w = w + 1;
Expand Down
38 changes: 22 additions & 16 deletions package.bluej
Original file line number Diff line number Diff line change
@@ -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
editor.fx.0.height=729
editor.fx.0.width=906
editor.fx.0.x=799
editor.fx.0.y=153
objectbench.height=101
objectbench.width=740
package.divider.horizontal=0.6
objectbench.width=694
package.divider.horizontal=0.5630522088353414
package.divider.vertical=0.8625954198473282
package.editor.height=671
package.editor.width=1139
package.editor.x=112
package.editor.y=89
package.editor.width=1147
package.editor.x=348
package.editor.y=85
package.frame.height=844
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
Expand Down Expand Up @@ -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