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

added by Usha #29

Open
wants to merge 4 commits 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
28 changes: 26 additions & 2 deletions WriteIFs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ 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(player1) == false)
{
displayGameOver(player1);
}

}

Expand All @@ -19,7 +23,14 @@ public String thermoSTAT(int room) {
// “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,12 +41,25 @@ 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();
}

}

Expand All @@ -46,7 +70,7 @@ public void checkFuel(double fuelLevel) {
*
*
* instance variables
* /
**/
int x;
int tt_t;
int tt_s;
Expand Down
98 changes: 79 additions & 19 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 @@ -18,9 +18,12 @@ public class WriteLoops {
public int oneToFive() {
int w = 0;

// Write a FOR loop that counts from 1 to 10.
// Write a FOR loop that counts from 1 to 5.
// calling
for ( int i = 0; i<5 ; i++)
{
w = w + 1;
}
// each time through the loop

// this will tell the test how many times the loop executed.
Expand All @@ -32,18 +35,25 @@ public int oneToTen() {

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

public int startAtTwentyOne() {
int w = 0;


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

return w;
Expand All @@ -54,7 +64,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,7 +78,10 @@ public int byTwoTo32() {

// Write a FOR loop from 0 to 32 by 2s.
// calling
w = w + 1;
for ( int i = 0 ; i>=32 ; i+=2)
{
w = w + 1;
}
// each time through the loop
return w;
}
Expand All @@ -75,7 +91,10 @@ public int countDownFrom5000() {

// Write a FOR loop from 1 to less than 5001 by 11s.
// calling
w = w + 1;
for ( int i = 5000 ; i>=1 ; i-=11)
{
w = w + 1;
}
// each time through the loop

return w;
Expand All @@ -87,28 +106,49 @@ 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;
}

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


// 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;
int w = 0;
for ( int i = 5 ; i<=105 ; i++)
{
if ( i <= 51)
{
//System.out.println("Hello Zipcode");
w = w+1;
}
else
{
System.out.println("Hello Zipcode");
}

// each time through the inner loop

}
return w;
}

public void simpleLoops() {
public void simpleLoops()
{
int i = 0;

// sample while loop
Expand All @@ -133,11 +173,14 @@ public int driveHome() {
int w = 0;

// you need to use a .equals for two Strings.

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

System.out.println("Honey, I’m Home!");

return w;
}
Expand All @@ -155,11 +198,13 @@ public int checkGameScore() {
int runningScore = 0;

// do your while loop here

while(runningScore < highestScore)
{
runningScore = currentScore + runningScore;
// calling
w = w + 1;
// each time through the inner loop

}
return w; // >= 3;
}

Expand All @@ -172,10 +217,14 @@ public boolean checkGameScoreDoWhile() {
int runningScore = 0;

// do your while loop here

do
{
runningScore = currentScore + runningScore;
// calling
w = w + 1;
// each time through the inner loop
} while(runningScore < highestScore-1) ;


return w >= 3;
}
Expand All @@ -188,9 +237,20 @@ public int checkServerStatus() {
int w = 0;
String adminPhoneNumber = "+1 202 456 1111";

while(serverIsRunning())
{
waitFor(5);
w = w + 1;
}

sendEmergencyText("Help!", adminPhoneNumber);
tryServerRestart("Help!", adminPhoneNumber);




// calling
w = w + 1;

// each time through the inner loop

return w;
Expand Down