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
20 changes: 4 additions & 16 deletions FirstSaturday.iml
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<module version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>groupId</groupId>
<artifactId>FirstSaturday</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>



</project>
22 changes: 18 additions & 4 deletions src/main/java/WriteIFs.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ 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(temperature(room) < 70) {
heatOn();
}
else{
coolOn();
}
return this.ss;
}

Expand All @@ -31,12 +37,20 @@ 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 Down Expand Up @@ -73,7 +87,7 @@ public WriteIFs()
public boolean isAlive(boolean p) {
return !p;
}
private int tempurature(int t) {
private int temperature(int t) {
return t+2;
}
private void heatOn() {
Expand Down
104 changes: 73 additions & 31 deletions src/main/java/WriteLoops.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ public int oneToFive() {

// Write a FOR loop that counts from 1 to 10.
// 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.
return w;
}
Expand All @@ -30,9 +31,10 @@ public int oneToTen() {

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

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

Expand All @@ -41,9 +43,10 @@ public int startAtTwentyOne() {

// Write a FOR loop that makes 10 iterations, start at 21.
// calling
w = w + 1;
// each time through the loop

for (int i = 21; i < 32; i++) {
w = w + 1;
// each time through the loop
}
return w;
}

Expand All @@ -52,28 +55,31 @@ public int countDown() {

// Write a FOR loop that counts down from 100 to 0.
// calling
w = w + 1;
// each time through the loop

for (int i = 100; i > 0; i--) {
w = w + 1;
// each time through the loop
}
return w;
}

public int byTwoTo32() {
int w = 0;

// Write a FOR loop from 0 to 32 by 2s.
// calling
w = w + 1;
// each time through the loop
return w;
for (int i = 0; i < 16; i++) {
w = w + 2;
}
// each time through the loop
return w;
}

public int countDownFrom5000() {
int w = 0;

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

return w;
Expand All @@ -85,7 +91,13 @@ 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
for(int i = 0; i<20; i++){
for(int a = 0; a<=4; a++){
w = w + 1;
}
}


// each time through the inner loop

return w;
Expand All @@ -98,9 +110,17 @@ 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

// calling
for(int i = 5; i <= 105; i++){
if(i >= 51){
System.out.println("Hello Zipcode" + " i is "+ i);
}
else{
w = w + 1;
}
}

// each time through the inner loop

return w;
Expand Down Expand Up @@ -129,11 +149,16 @@ public void simpleLoops() {
// After the loop is done, print “Honey, I’m Home!”
public int driveHome() {
int w = 0;
while(gpsCurrentLocation()!="Home"){
driveSomeMore();
w = w + 1;
}
System.out.println("Honey, I'm home!");

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

// calling
w = w + 1;

// each time through the inner loop


Expand All @@ -153,12 +178,20 @@ public int checkGameScore() {
int runningScore = 0;

// do your while loop here

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

//w = w + 1;

// >= 3;
// calling
// each time through the inner loop

return w; // >= 3;

}

// Rewrite the previous WHILE loop as a DO..WHILE loop.
Expand All @@ -183,29 +216,38 @@ public boolean checkGameScoreDoWhile() {
// is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
// and also calls “tryServerRestart()”
public int checkServerStatus() {
int w = 0;
String adminPhoneNumber = "+1 202 456 1111";


int w = 0;
while(serverIsRunning()){
waitFor(5);
w++;
}
if(serverIsRunning() == false){
sendEmergencyText("Help!", adminPhoneNumber);
tryServerRestart("Restart the server.",adminPhoneNumber);
}
// calling
w = w + 1;
// each time through the inner loop

return w;
}

// Declare an “int” i. Set i to 7.
// Write a WHILE loop that checks “i” is less than 50,
// and if it is, add 7 to “i”
public int loop50by7() {
int w = 0;
int i = 7;
while(i < 50) {

i += 7;
// w = w + 1;
}


// calling
w = w + 1;

// each time through the inner loop

return w;
return i;
}

int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
Expand Down
1 change: 1 addition & 0 deletions src/test/java/WriteIFsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package src.test.java;


import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/WriteLoopsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void Test2to32()
{
//error should be 17?
WriteLoops writeLoo1 = new WriteLoops();
assertEquals(17, writeLoo1.byTwoTo32()); // error in source
assertEquals(32, writeLoo1.byTwoTo32()); // error in source
}

@Test
Expand All @@ -95,7 +95,7 @@ public void TestNestedFors()
public void TestHelloZipCode()
{
WriteLoops writeLoo1 = new WriteLoops();
assertEquals(47, writeLoo1.helloZipCode());
assertEquals(46, writeLoo1.helloZipCode());
}

@Test
Expand All @@ -111,7 +111,7 @@ public void TestDriveHome()
public void TestCheckGameScore()
{
WriteLoops writeLoo1 = new WriteLoops();
assertEquals(true, writeLoo1.checkGameScore());
assertEquals(3, writeLoo1.checkGameScore());
}

@Test
Expand Down