Преглед изворни кода

checkpoint progress Sat Morn

Seth пре 6 година
родитељ
комит
c87e45f25b
3 измењених фајлова са 124 додато и 84 уклоњено
  1. 3
    0
      WriteIFs.java
  2. 110
    73
      WriteLoops.java
  3. 11
    11
      package.bluej

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

@@ -11,6 +11,9 @@ public class WriteIFs
11 11
     public void playerDied(boolean player1) {
12 12
         // Write an IF statement that checks “player1.isAlive()” 
13 13
         // and if that’s false, calls “displayGameOver(player1)”
14
+        if (player1.isAlive(false)) {
15
+        
16
+        }
14 17
      
15 18
     }
16 19
     

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

@@ -17,11 +17,11 @@ public class WriteLoops {
17 17
 
18 18
     public int oneToFive() {
19 19
         int w = 0;
20
-
21 20
         // Write a FOR loop that counts from 1 to 10.
22
-            // calling
23
-            w = w + 1;
24
-            // each time through the loop
21
+        // calling
22
+        for(int i=1; i<=5; i++) {
23
+            w += 1;
24
+        }   // each time through the loop
25 25
 
26 26
         // this will tell the test how many times the loop executed.
27 27
         return w;
@@ -32,9 +32,11 @@ public class WriteLoops {
32 32
 
33 33
         // Write a FOR loop that counts from 1 to 10.
34 34
         // calling
35
-        w = w + 1;
35
+        for(int i=1; i<=10; i++) {
36
+            w += 1;
37
+        }
36 38
         // each time through the loop
37
-        
39
+
38 40
         return w;
39 41
     }
40 42
 
@@ -43,9 +45,11 @@ public class WriteLoops {
43 45
 
44 46
         // Write a FOR loop that makes 10 iterations, start at 21.
45 47
         // calling
46
-        w = w + 1;
48
+        for(int i=21; i<=31; i++) {
49
+            w += 1;
50
+        }
47 51
         // each time through the loop
48
-        
52
+
49 53
         return w;
50 54
     }
51 55
 
@@ -54,9 +58,11 @@ public class WriteLoops {
54 58
 
55 59
         // Write a FOR loop that counts down from 100 to 0.
56 60
         // calling
57
-        w = w + 1;
61
+        for(int i=100; i>=1; i--) {
62
+            w += 1;
63
+        }
58 64
         // each time through the loop
59
-        
65
+
60 66
         return w;
61 67
     }
62 68
 
@@ -65,7 +71,9 @@ public class WriteLoops {
65 71
 
66 72
         // Write a FOR loop from 0 to 32 by 2s.
67 73
         // calling
68
-        w = w + 1;
74
+        for(int i=32; i<=0; i-=2) {
75
+            w += 1;
76
+        }
69 77
         // each time through the loop
70 78
         return w;
71 79
     }
@@ -75,9 +83,11 @@ public class WriteLoops {
75 83
 
76 84
         // Write a FOR loop from 1 to less than 5001 by 11s.
77 85
         // calling
78
-        w = w + 1;
86
+        for(int i=1; i<5000; i+=11) {
87
+            w += 1;
88
+        }
79 89
         // each time through the loop
80
-        
90
+
81 91
         return w;
82 92
     }
83 93
 
@@ -86,9 +96,14 @@ public class WriteLoops {
86 96
 
87 97
         // Write a nested FOR loop(s), where one counts from
88 98
         // 0 to less than 20 and the inner one counts from 0 to 4
89
-                // calling
90
-                w = w + 1;
91
-                // each time through the inner loop
99
+        // calling
100
+        for(int i=0; i>20; ++i) {
101
+            for(int j=0; j>=4; ++j) {
102
+                w += 1;
103
+            }
104
+        }
105
+
106
+        // each time through the inner loop
92 107
 
93 108
         return w;
94 109
     }
@@ -100,11 +115,17 @@ public class WriteLoops {
100 115
         // statement inside the loop that checks the
101 116
         // loop index counter and if it’s greater than 51,
102 117
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103
-
104
-                // calling
105
-                w = w + 1;
106
-            // each time through the inner loop
118
+        for(int i=5; i<=105; i++) {
119
+           if(i <= 51){
120
+               w += 1;
121
+            } else {
122
+                System.out.println("Hello Zipcode");
123
+            }
124
+        }
125
+        // calling
107 126
         
127
+        // each time through the inner loop
128
+
108 129
         return w;
109 130
     }
110 131
 
@@ -133,13 +154,21 @@ public class WriteLoops {
133 154
         int w = 0;
134 155
 
135 156
         // you need to use a .equals for two Strings.
136
-
137
-            // calling
138
-            w = w + 1;
139
-            // each time through the inner loop
157
+        while(gpsCurrentLocation().equals("Home") == false){
158
+            if(w<6){
159
+            driveSomeMore();
160
+            w++;
161
+            } else {
162
+            gpsCurrentLocation().equals("Home");
163
+            }
164
+        }
140 165
         
166
+        System.out.println("Honey, I’m Home!");
167
+        // calling
168
+        
169
+        // each time through the inner loop
141 170
 
142
-            return w;
171
+        return w;
143 172
     }
144 173
 
145 174
     // Getting harder...
@@ -153,29 +182,38 @@ public class WriteLoops {
153 182
         int highestScore = 236;
154 183
         int currentScore = gameNextScore();
155 184
         int runningScore = 0;
185
+        
186
+        while(runningScore < currentScore){
187
+             currentScore += runningScore;
188
+             currentScore += gameNextScore();
189
+             w = w + 1;
190
+        }
191
+        
156 192
 
157
-        // do your while loop here
158
- 
159
-            // calling
160
-            w = w + 1;
161
-            // each time through the inner loop
193
+        // calling
162 194
         
163
-        return w; // >= 3;
195
+        // each time through the inner loop
196
+
197
+        return w; //>= 3;
164 198
     }
165 199
 
166 200
     // Rewrite the previous WHILE loop as a DO..WHILE loop.
167 201
     // Notice how the “runningScore” variable usage is different.
168 202
     public boolean checkGameScoreDoWhile() {
169 203
         int w = 0;
170
-        int highestScore = 236;
204
+        int highestScore = 236; 
171 205
         int currentScore = gameNextScore();
172 206
         int runningScore = 0;
173 207
 
174 208
         // do your while loop here
175
-
176
-            // calling
209
+        do {
210
+            currentScore += runningScore;
211
+            currentScore += gameNextScore();
177 212
             w = w + 1;
178
-            // each time through the inner loop
213
+        } while(runningScore < highestScore);
214
+        // calling
215
+        
216
+        // each time through the inner loop
179 217
 
180 218
         return w >= 3;
181 219
     }
@@ -187,12 +225,11 @@ public class WriteLoops {
187 225
     public int checkServerStatus() {
188 226
         int w = 0;
189 227
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
191 228
 
192 229
         // calling
193 230
         w = w + 1;
194 231
         // each time through the inner loop
195
-        
232
+
196 233
         return w;
197 234
     }
198 235
 
@@ -201,12 +238,15 @@ public class WriteLoops {
201 238
     // and if it is, add 7 to “i”
202 239
     public int loop50by7() {
203 240
         int w = 0;
204
-
205
-
206
-            // calling
207
-            w = w + 1;
208
-            // each time through the inner loop
241
+        int i = 0;
242
+        // calling
243
+        while(i<50) {
244
+        i+=7;
245
+        w = w + 1;
246
+        }
209 247
         
248
+        // each time through the inner loop
249
+
210 250
         return w;
211 251
     }
212 252
 
@@ -239,11 +279,10 @@ public class WriteLoops {
239 279
         int w = 0;
240 280
         int sumOfThrees = 0;
241 281
 
242
- 
243
-            // calling
244
-            w = w + 1;
245
-            // each time through the inner loop
246
-        
282
+        // calling
283
+        w = w + 1;
284
+        // each time through the inner loop
285
+
247 286
         System.out.print("The Sum is ");
248 287
         System.out.println(sumOfThrees);
249 288
 
@@ -256,11 +295,10 @@ public class WriteLoops {
256 295
         int w = 0;
257 296
         int sumOfThrees = 0;
258 297
 
259
- 
260
-            // calling
261
-            w = w + 1;
262
-            // each time through the inner loop
263
-        
298
+        // calling
299
+        w = w + 1;
300
+        // each time through the inner loop
301
+
264 302
         System.out.print("The Sum is ");
265 303
         System.out.println(sumOfThrees);
266 304
 
@@ -279,11 +317,11 @@ public class WriteLoops {
279 317
         boolean onTime = true;
280 318
 
281 319
         // ADD YOUR CODE here.
282
- 
283
-            // be sure to call
284
-            w = w + 1;
285
-            // each time inside the loop
286
-        
320
+
321
+        // be sure to call
322
+        w = w + 1;
323
+        // each time inside the loop
324
+
287 325
         return w;
288 326
     }
289 327
 
@@ -296,11 +334,10 @@ public class WriteLoops {
296 334
         int w = 0;
297 335
         int numberOfVotes = voteTallies.length;
298 336
 
299
- 
300
-            // calling
301
-            w = w + 1;
302
-            // each time through the inner loop
303
-        
337
+        // calling
338
+        w = w + 1;
339
+        // each time through the inner loop
340
+
304 341
         return w;
305 342
     }
306 343
 
@@ -311,11 +348,10 @@ public class WriteLoops {
311 348
         int w = 0;
312 349
         int numberOfVotes = voteTallies.length;
313 350
 
351
+        // calling
352
+        w = w + 1;
353
+        // each time through the inner loop
314 354
 
315
-            // calling
316
-            w = w + 1;
317
-            // each time through the inner loop
318
-        
319 355
         return w;
320 356
     }
321 357
 
@@ -378,14 +414,15 @@ public class WriteLoops {
378 414
     //         return (i >= 3);
379 415
     //     };
380 416
     // };
381
-        private int summer = 0;
382
-        private boolean isSummer() {
383
-            if (summer == 3) {
384
-                return true;
385
-            }
386
-            summer++;
387
-            return false;
417
+    private int summer = 0;
418
+    private boolean isSummer() {
419
+        if (summer == 3) {
420
+            return true;
388 421
         }
422
+        summer++;
423
+        return false;
424
+    }
425
+
389 426
     private void sendEmergencyText(String mesg, String phone) {
390 427
     }
391 428
 

+ 11
- 11
package.bluej Прегледај датотеку

@@ -7,18 +7,18 @@ dependency2.to=WriteIFs
7 7
 dependency2.type=UsesDependency
8 8
 editor.fx.0.height=722
9 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
10
+editor.fx.0.x=319
11
+editor.fx.0.y=48
12
+objectbench.height=104
13
+objectbench.width=692
14 14
 package.divider.horizontal=0.6
15
-package.divider.vertical=0.8625954198473282
16
-package.editor.height=671
17
-package.editor.width=1139
18
-package.editor.x=112
19
-package.editor.y=89
20
-package.frame.height=844
21
-package.frame.width=1265
15
+package.divider.vertical=0.8238095238095238
16
+package.editor.height=512
17
+package.editor.width=590
18
+package.editor.x=100
19
+package.editor.y=23
20
+package.frame.height=688
21
+package.frame.width=716
22 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true