Jacqueline Joson пре 6 година
родитељ
комит
48eb7e5d47
3 измењених фајлова са 26 додато и 21 уклоњено
  1. 2
    2
      WriteIFs.java
  2. 23
    19
      WriteLoops.java
  3. 1
    0
      WriteLoopsTest.java

+ 2
- 2
WriteIFs.java Прегледај датотеку

@@ -16,7 +16,7 @@ public class WriteIFs
16 16
  
17 17
     public void playerDied(boolean player1) {
18 18
         if (!isAlive(player1)); {
19
-            return displayGameOver;
19
+            displayGameOver(player1);
20 20
         }// Write an IF statement that checks “player1.isAlive()” 
21 21
         // and if that’s false, calls “displayGameOver(player1)”
22 22
      
@@ -35,7 +35,7 @@ public class WriteIFs
35 35
     }
36 36
 
37 37
     public void fireplaceControl(Object fireplace1) {
38
-        if ((oo2 < 50) && (oo1 < 62)) {
38
+        if ((oo1 < 50) && (oo2 < 62)) {
39 39
             startAFire(fireplace1); 
40 40
         }
41 41
             // Write an IF statement that checks 

+ 23
- 19
WriteLoops.java Прегледај датотеку

@@ -18,7 +18,7 @@ public class WriteLoops {
18 18
     public int oneToFive() {
19 19
         int w = 0;
20 20
 
21
-        for (w = 0; w < 5; w++); {// Write a FOR loop that counts from 1 to 10.
21
+        for (int i = 0; i < 5; i++) {// Write a FOR loop that counts from 1 to 10.
22 22
             // calling
23 23
             w = w + 1;
24 24
         }// each time through the loop
@@ -30,8 +30,8 @@ public class WriteLoops {
30 30
     public int oneToTen() {
31 31
         int w = 0;
32 32
 
33
-        for (w = 0; w < 10; w++); {// Write a FOR loop that counts from 1 to 10.
34
-        w = w + 1;
33
+        for (int i = 0; i < 10; i++) {// Write a FOR loop that counts from 1 to 10.
34
+            w = w + 1;
35 35
         }// each time through the loop
36 36
         
37 37
         return w;
@@ -40,9 +40,9 @@ public class WriteLoops {
40 40
     public int startAtTwentyOne() {
41 41
         int w = 0;
42 42
 
43
-        for (w = 21; w < 31; w++) {// Write a FOR loop that makes 10 iterations, start at 21.
43
+        for (int i = 21; i < 31; i++) {// Write a FOR loop that makes 10 iterations, start at 21.
44 44
         // calling
45
-        w = w + 1;
45
+            w = w + 1;
46 46
         }// each time through the loop
47 47
         System.out.print(w);
48 48
         return w;
@@ -51,7 +51,7 @@ public class WriteLoops {
51 51
     public int countDown() {
52 52
         int w = 0;
53 53
 
54
-        for (w = 100; w >= 0; w--;) {// Write a FOR loop that counts down from 100 to 0.
54
+        for (int i = 100; i >= 0; i--) {// Write a FOR loop that counts down from 100 to 0.
55 55
         // calling
56 56
         w = w + 1;
57 57
         }// each time through the loop
@@ -62,7 +62,7 @@ public class WriteLoops {
62 62
     public int byTwoTo32() {
63 63
         int w = 0;
64 64
 
65
-        for (w = 0; w < 32; w += 2) {// Write a FOR loop from 0 to 32 by 2s.
65
+        for (int i = 0; i <= 32; i += 2) {// Write a FOR loop from 0 to 32 by 2s.
66 66
         // calling
67 67
         w = w + 1;
68 68
         }// each time through the loop
@@ -72,38 +72,40 @@ public class WriteLoops {
72 72
     public int countDownFrom5000() {
73 73
         int w = 0;
74 74
 
75
-        // Write a FOR loop from 1 to less than 5001 by 11s.
75
+        for (int i = 1; i <5001; i +=11) {// Write a FOR loop from 1 to less than 5001 by 11s.
76 76
         // calling
77 77
         w = w + 1;
78 78
         // each time through the loop
79
-        
79
+       }
80 80
         return w;
81 81
     }
82 82
 
83 83
     public int nestedFors() {
84 84
         int w = 0;
85 85
 
86
-        // Write a nested FOR loop(s), where one counts from
86
+        for (int i = 0; i < 20; i++) {
87
+            for (int j = 0; i <= 4; i++) {// Write a nested FOR loop(s), where one counts from
87 88
         // 0 to less than 20 and the inner one counts from 0 to 4
88 89
                 // calling
89 90
                 w = w + 1;
90
-                // each time through the inner loop
91
-
91
+            }
92
+        }
92 93
         return w;
93 94
     }
94 95
 
95 96
     public int helloZipCode() {
96 97
         int w = 0;
97 98
 
99
+        for (w = 5; w < 105; w++) {
100
+            if (w > 51) {
101
+                System.out.print("Hello Zipcode");
102
+                w = w + 1;
103
+            }
104
+        }
98 105
         // Write a FOR loop that counts from 5 to 105. Put an IF
99 106
         // statement inside the loop that checks the
100 107
         // loop index counter and if it’s greater than 51,
101
-        // prints “Hello Zipcode” instead of the statement w = w + 1;
102
-
103
-                // calling
104
-                w = w + 1;
105
-            // each time through the inner loop
106
-        
108
+        // prints “Hello Zipcode” instead of the statement w = w + 1
107 109
         return w;
108 110
     }
109 111
 
@@ -114,7 +116,7 @@ public class WriteLoops {
114 116
         while (i <= 5) {
115 117
             System.out.println("Eww.");
116 118
             i = i + 1;
117
-        }
119
+        } //As long as i <= 5, it will print out "Eww." on the screen
118 120
 
119 121
         // sample do...while loop
120 122
         i = 8;
@@ -123,6 +125,8 @@ public class WriteLoops {
123 125
             i = i - 1;
124 126
         } while (i > 0);
125 127
         // what's the primary difference between them?!?
128
+        /* the do part of the loop is the constant and the while is the
129
+        amount for which that will occur */ 
126 130
     }
127 131
 
128 132
     // Write a WHILE loop that checks “gpsCurrentLocation()”

+ 1
- 0
WriteLoopsTest.java Прегледај датотеку

@@ -72,6 +72,7 @@ public class WriteLoopsTest
72 72
     {
73 73
         WriteLoops writeLoo1 = new WriteLoops();
74 74
         assertEquals(0, writeLoo1.byTwoTo32());
75
+        //test not passing 
75 76
     }
76 77
 
77 78
     @Test