ソースを参照

all tests pass in both pbjects and untested methods writted. Lab essentially complete.

Margaret Pierse 8 年 前
コミット
01e01cb3f3
共有5 個のファイルを変更した70 個の追加60 個の削除を含む
  1. 7
    7
      WriteIFs.java
  2. 7
    7
      WriteIFsTest.java
  3. 38
    28
      WriteLoops.java
  4. 1
    1
      WriteLoopsTest.java
  5. 17
    17
      package.bluej

+ 7
- 7
WriteIFs.java ファイルの表示

@@ -27,15 +27,15 @@ public class WriteIFs
27 27
         oo2 = 49;
28 28
     }
29 29
 
30
-    // public void playerDied(boolean player1) {
31
-        // //Write an IF statement that checks “player1.isAlive()” 
32
-        // //and if that’s false, calls “displayGameOver(player1)”
30
+    public void playerDied(boolean player1) {
31
+        //Write an IF statement that checks “player1.isAlive()” 
32
+        //and if that’s false, calls “displayGameOver(player1)”
33 33
 
34
-        // if (player1) {
35
-            // displayGameOver(player1);
36
-        // }
34
+        if (!isAlive(player1)) {
35
+            displayGameOver(player1);
36
+        }
37 37
 
38
-    // }
38
+    }
39 39
 
40 40
     public String thermoSTAT(int room) {
41 41
         // Write an IF statement that checks the 

+ 7
- 7
WriteIFsTest.java ファイルの表示

@@ -43,13 +43,13 @@ public class WriteIFsTest
43 43
     {
44 44
     }
45 45
 
46
-    // @Test
47
-    // public void TestIfs()
48
-    // {
49
-        // WriteIFs writeIFs1 = new WriteIFs();
50
-        // writeIFs1.playerDied(true);
51
-        // assertEquals("Game Over!", writeIFs1.ss);
52
-    // }
46
+    @Test
47
+    public void TestIfs()
48
+    {
49
+        WriteIFs writeIFs1 = new WriteIFs();
50
+        writeIFs1.playerDied(true);
51
+        assertEquals("Game Over!", writeIFs1.ss);
52
+    }
53 53
 
54 54
 
55 55
     @Test

+ 38
- 28
WriteLoops.java ファイルの表示

@@ -74,7 +74,7 @@ public class WriteLoops {
74 74
         // Write a FOR loop from 0 to 32 by 2s.
75 75
         // calling
76 76
         for (int i=0; i<32; i+=2){
77
-            w = w + 0;
77
+            w = w + 1;
78 78
         }
79 79
         // each time through the loop
80 80
         return w;
@@ -215,7 +215,7 @@ public class WriteLoops {
215 215
         // each time through the inner loop
216 216
         if (!serverIsRunning()){
217 217
             sendEmergencyText("Help!", adminPhoneNumber);
218
-            tryServerRestart("Help!", adminPhoneNumber);
218
+            tryServerRestart("Restart my server please.", adminPhoneNumber);
219 219
         }
220 220
         return w;
221 221
     }
@@ -225,11 +225,12 @@ public class WriteLoops {
225 225
     // and if it is, add 7 to “i”
226 226
     public int loop50by7() {
227 227
         int w = 0;
228
-
229
-        // calling
230
-        w = w + 1;
231
-        // each time through the inner loop
232
-
228
+        int i = 7;
229
+        while (i<59) {
230
+            // calling
231
+            i += 7;
232
+            // each time through the inner loop
233
+        }
233 234
         return w;
234 235
     }
235 236
 
@@ -244,7 +245,7 @@ public class WriteLoops {
244 245
 
245 246
         // this is a so called Enhanced for loop
246 247
         for (int index : threes_array) {
247
-            sumOfThrees = sumOfThrees + threes_array[index];
248
+            sumOfThrees = sumOfThrees + index;
248 249
             // calling
249 250
             w = w + 1;
250 251
             // each time through the inner loop
@@ -259,17 +260,19 @@ public class WriteLoops {
259 260
     // rewrite the loop inside of "foo()" as a standard for loop
260 261
     // with 'i' as its index variable.
261 262
     public int rewriteFooAsFor() {
262
-        int w = 0;
263
+
263 264
         int sumOfThrees = 0;
264 265
 
265
-        // calling
266
-        w = w + 1;
267
-        // each time through the inner loop
266
+        for (int w=0; w<threes_array.length; w++ ){
267
+            // calling
268
+            sumOfThrees = sumOfThrees + 1;
268 269
 
270
+            // each time through the inner loop
271
+        }
269 272
         System.out.print("The Sum is ");
270 273
         System.out.println(sumOfThrees);
271 274
 
272
-        return w;
275
+        return sumOfThrees;
273 276
     }
274 277
 
275 278
     // Ponder this: can all WHILE loops be rewritten as FOR loops?
@@ -278,10 +281,12 @@ public class WriteLoops {
278 281
         int w = 0;
279 282
         int sumOfThrees = 0;
280 283
 
281
-        // calling
282
-        w = w + 1;
283
-        // each time through the inner loop
284
-
284
+        while (sumOfThrees < threes_array.length){
285
+            // calling
286
+            sumOfThrees = sumOfThrees + w;
287
+            w = w + 1;
288
+            // each time through the inner loop
289
+        }
285 290
         System.out.print("The Sum is ");
286 291
         System.out.println(sumOfThrees);
287 292
 
@@ -298,13 +303,16 @@ public class WriteLoops {
298 303
     public int manageYardAndJunior() {
299 304
         int w = 0;
300 305
         boolean onTime = true;
301
-
302
-        // ADD YOUR CODE here.
303
-
304
-        // be sure to call
305
-        w = w + 1;
306
-        // each time inside the loop
307
-
306
+        boolean yardNeedsMowed = true;
307
+        while(isSummer()){
308
+            // ADD YOUR CODE here.
309
+            if(yardNeedsMowed){
310
+                yellAtJuniorToMowLawn();}
311
+            // be sure to call
312
+            w = w + 1;
313
+            // each time inside the loop
314
+        }
315
+        sendJuniorBackToSchool("Go to school");
308 316
         return w;
309 317
     }
310 318
 
@@ -317,11 +325,12 @@ public class WriteLoops {
317 325
     public int tallyVote1() {
318 326
         int w = 0;
319 327
         int numberOfVotes = voteTallies.length;
320
-
328
+for (int idx=0; idx< voteTallies.length; idx++){
321 329
         // calling
330
+        System.out.println(voteTallies[idx]);
322 331
         w = w + 1;
323 332
         // each time through the inner loop
324
-
333
+    }
325 334
         return w;
326 335
     }
327 336
 
@@ -331,11 +340,12 @@ public class WriteLoops {
331 340
     public int tallyVote2() {
332 341
         int w = 0;
333 342
         int numberOfVotes = voteTallies.length;
334
-
343
+while (w<numberOfVotes){
335 344
         // calling
345
+        System.out.println(voteTallies[w]);
336 346
         w = w + 1;
337 347
         // each time through the inner loop
338
-
348
+    }
339 349
         return w;
340 350
     }
341 351
 

+ 1
- 1
WriteLoopsTest.java ファイルの表示

@@ -71,7 +71,7 @@ public class WriteLoopsTest
71 71
     public void Test2to32()
72 72
     {
73 73
         WriteLoops writeLoo1 = new WriteLoops();
74
-        assertEquals(0, writeLoo1.byTwoTo32());
74
+        assertEquals(16, writeLoo1.byTwoTo32());
75 75
     }
76 76
 
77 77
     @Test

+ 17
- 17
package.bluej ファイルの表示

@@ -1,24 +1,24 @@
1 1
 #BlueJ package file
2
-dependency1.from=WriteLoopsTest
3
-dependency1.to=WriteLoops
2
+dependency1.from=WriteIFsTest
3
+dependency1.to=WriteIFs
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=WriteIFsTest
6
-dependency2.to=WriteIFs
5
+dependency2.from=WriteLoopsTest
6
+dependency2.to=WriteLoops
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
9
-editor.fx.0.width=800
10
-editor.fx.0.x=560
11
-editor.fx.0.y=118
12
-objectbench.height=101
13
-objectbench.width=740
14
-package.divider.horizontal=0.6
15
-package.divider.vertical=0.8625954198473282
16
-package.editor.height=671
17
-package.editor.width=1139
8
+editor.fx.0.height=812
9
+editor.fx.0.width=909
10
+editor.fx.0.x=530
11
+editor.fx.0.y=23
12
+objectbench.height=97
13
+objectbench.width=560
14
+package.divider.horizontal=0.6399548532731377
15
+package.divider.vertical=0.8620689655172413
16
+package.editor.height=643
17
+package.editor.width=780
18 18
 package.editor.x=112
19
-package.editor.y=89
20
-package.frame.height=844
21
-package.frame.width=1265
19
+package.editor.y=23
20
+package.frame.height=812
21
+package.frame.width=906
22 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true