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

Program works #28

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
29 changes: 22 additions & 7 deletions WriteIFs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@
/**
* Write a description of class WriteIFs here.
*
* @author (your name)
* @version (a version number or a date)
* @author Maira Botelho
* @version 10.18.2019
*/
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);
}
}

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



return this.ss;
}

Expand All @@ -30,12 +35,20 @@ public void fireplaceControl(Object fireplace1) {
// AND
// “insideTemp()” is less than 62,
// calls “startAFire(fireplace1)”
if(outsideTemp() < 50 && insideTemp() < 62){
startAFire(fireplace1);
}else{
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 +59,9 @@ public void checkFuel(double fuelLevel) {
*
*
* instance variables
* /
*/


int x;
int tt_t;
int tt_s;
Expand Down
141 changes: 98 additions & 43 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 @@ -20,7 +20,9 @@ public int oneToFive() {

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

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

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

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

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

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

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

return w;
Expand All @@ -65,7 +73,13 @@ public int byTwoTo32() {

// Write a FOR loop from 0 to 32 by 2s.
// calling
w = w + 1;
for(int x = 0; x < 32; x++){
w = w + 1;
x = x + 1;
}



// each time through the loop
return w;
}
Expand All @@ -75,7 +89,10 @@ public int countDownFrom5000() {

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

return w;
Expand All @@ -87,7 +104,11 @@ 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 x = 0; x < 20; x++){
for(int y = 0; y <= 4; y++){
w = w + 1;
}
}
// each time through the inner loop

return w;
Expand All @@ -100,11 +121,15 @@ 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;

// calling
for(int x = 5; x < 105; x++){

if(x > 51){
System.out.println("Hello Zipcode");
}else{
w = w + 1;
}
// each time through the inner loop

}
return w;
}

Expand All @@ -124,6 +149,9 @@ public void simpleLoops() {
i = i - 1;
} while (i > 0);
// what's the primary difference between them?!?
/*In the do..while, the loop is executed before checking the condition,so it will be executed at least once even if
* the paramenters are not the same. In the while loop the loop checks for the paramenter, se it needs to be the same
to be executed.*/
}

// Write a WHILE loop that checks “gpsCurrentLocation()”
Expand All @@ -133,11 +161,13 @@ public int driveHome() {
int w = 0;

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

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

w = w + 1;
}

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

return w;
}
Expand All @@ -154,13 +184,15 @@ public int checkGameScore() {
int currentScore = gameNextScore();
int runningScore = 0;

// do your while loop here

// calling
while(runningScore < highestScore){

runningScore = runningScore + currentScore;
currentScore = gameNextScore();
w = w + 1;
// each time through the inner loop

}
return w; // >= 3;

}

// Rewrite the previous WHILE loop as a DO..WHILE loop.
Expand All @@ -170,13 +202,14 @@ public boolean checkGameScoreDoWhile() {
int highestScore = 236;
int currentScore = gameNextScore();
int runningScore = 0;

// do your while loop here

// calling

do{

runningScore = runningScore + currentScore;
currentScore = gameNextScore();
w = w + 1;
// each time through the inner loop

}while(runningScore < highestScore);
return w >= 3;
}

Expand All @@ -189,10 +222,16 @@ public int checkServerStatus() {
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);
tryServerRestart("Help!", adminPhoneNumber);
}
return w;
}

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


// calling
while (i < 50){
i = i + 7;
w = w + 1;
}
// each time through the inner loop

return w;
Expand Down Expand Up @@ -239,9 +280,10 @@ public int rewriteFooAsFor() {
int w = 0;
int sumOfThrees = 0;


// calling
w = w + 1;
for(int i = 0; i < threes_array.length; i++){
sumOfThrees = sumOfThrees + threes_array[i];
w = w + 1;
}
// each time through the inner loop

System.out.print("The Sum is ");
Expand All @@ -255,10 +297,13 @@ public int rewriteFooAsFor() {
public int rewriteFooAsWhile() {
int w = 0;
int sumOfThrees = 0;
int i = 0;


// calling
w = w + 1;
while( i < threes_array.length){

sumOfThrees = sumOfThrees + threes_array[i];
w = w + 1;
}
// each time through the inner loop

System.out.print("The Sum is ");
Expand All @@ -277,11 +322,18 @@ public int rewriteFooAsWhile() {
public int manageYardAndJunior() {
int w = 0;
boolean onTime = true;

// ADD YOUR CODE here.

// be sure to call
boolean yardNeedsMowed = true;

while(isSummer() == true){

if(yardNeedsMowed == true){
yellAtJuniorToMowLawn();
}

sendJuniorBackToSchool("Go back to scool!");

w = w + 1;
}
// each time inside the loop

return w;
Expand All @@ -295,10 +347,11 @@ public int manageYardAndJunior() {
public int tallyVote1() {
int w = 0;
int numberOfVotes = voteTallies.length;


// calling
for(int i = 0; i < numberOfVotes; i++){
System.out.print(voteTallies[i]);
w = w + 1;
}
// each time through the inner loop

return w;
Expand All @@ -310,10 +363,12 @@ public int tallyVote1() {
public int tallyVote2() {
int w = 0;
int numberOfVotes = voteTallies.length;
int idx = 0;


// calling
while(idx < numberOfVotes){
System.out.print(voteTallies[idx]);
w = w + 1;
}
// each time through the inner loop

return w;
Expand Down
2 changes: 1 addition & 1 deletion WriteLoopsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void TestCountDown()
public void Test2to32()
{
WriteLoops writeLoo1 = new WriteLoops();
assertEquals(0, writeLoo1.byTwoTo32());
assertEquals(16, writeLoo1.byTwoTo32());
}

@Test
Expand Down
Loading