Browse Source

checkpoint progress Sat Morn

Seth 6 years ago
parent
commit
c87e45f25b
3 changed files with 124 additions and 84 deletions
  1. 3
    0
      WriteIFs.java
  2. 110
    73
      WriteLoops.java
  3. 11
    11
      package.bluej

+ 3
- 0
WriteIFs.java View File

11
     public void playerDied(boolean player1) {
11
     public void playerDied(boolean player1) {
12
         // Write an IF statement that checks “player1.isAlive()” 
12
         // Write an IF statement that checks “player1.isAlive()” 
13
         // and if that’s false, calls “displayGameOver(player1)”
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 View File

17
 
17
 
18
     public int oneToFive() {
18
     public int oneToFive() {
19
         int w = 0;
19
         int w = 0;
20
-
21
         // Write a FOR loop that counts from 1 to 10.
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
         // this will tell the test how many times the loop executed.
26
         // this will tell the test how many times the loop executed.
27
         return w;
27
         return w;
32
 
32
 
33
         // Write a FOR loop that counts from 1 to 10.
33
         // Write a FOR loop that counts from 1 to 10.
34
         // calling
34
         // calling
35
-        w = w + 1;
35
+        for(int i=1; i<=10; i++) {
36
+            w += 1;
37
+        }
36
         // each time through the loop
38
         // each time through the loop
37
-        
39
+
38
         return w;
40
         return w;
39
     }
41
     }
40
 
42
 
43
 
45
 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
46
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
47
         // calling
46
-        w = w + 1;
48
+        for(int i=21; i<=31; i++) {
49
+            w += 1;
50
+        }
47
         // each time through the loop
51
         // each time through the loop
48
-        
52
+
49
         return w;
53
         return w;
50
     }
54
     }
51
 
55
 
54
 
58
 
55
         // Write a FOR loop that counts down from 100 to 0.
59
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
60
         // calling
57
-        w = w + 1;
61
+        for(int i=100; i>=1; i--) {
62
+            w += 1;
63
+        }
58
         // each time through the loop
64
         // each time through the loop
59
-        
65
+
60
         return w;
66
         return w;
61
     }
67
     }
62
 
68
 
65
 
71
 
66
         // Write a FOR loop from 0 to 32 by 2s.
72
         // Write a FOR loop from 0 to 32 by 2s.
67
         // calling
73
         // calling
68
-        w = w + 1;
74
+        for(int i=32; i<=0; i-=2) {
75
+            w += 1;
76
+        }
69
         // each time through the loop
77
         // each time through the loop
70
         return w;
78
         return w;
71
     }
79
     }
75
 
83
 
76
         // Write a FOR loop from 1 to less than 5001 by 11s.
84
         // Write a FOR loop from 1 to less than 5001 by 11s.
77
         // calling
85
         // calling
78
-        w = w + 1;
86
+        for(int i=1; i<5000; i+=11) {
87
+            w += 1;
88
+        }
79
         // each time through the loop
89
         // each time through the loop
80
-        
90
+
81
         return w;
91
         return w;
82
     }
92
     }
83
 
93
 
86
 
96
 
87
         // Write a nested FOR loop(s), where one counts from
97
         // Write a nested FOR loop(s), where one counts from
88
         // 0 to less than 20 and the inner one counts from 0 to 4
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
         return w;
108
         return w;
94
     }
109
     }
100
         // statement inside the loop that checks the
115
         // statement inside the loop that checks the
101
         // loop index counter and if it’s greater than 51,
116
         // loop index counter and if it’s greater than 51,
102
         // prints “Hello Zipcode” instead of the statement w = w + 1;
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
         return w;
129
         return w;
109
     }
130
     }
110
 
131
 
133
         int w = 0;
154
         int w = 0;
134
 
155
 
135
         // you need to use a .equals for two Strings.
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
     // Getting harder...
174
     // Getting harder...
153
         int highestScore = 236;
182
         int highestScore = 236;
154
         int currentScore = gameNextScore();
183
         int currentScore = gameNextScore();
155
         int runningScore = 0;
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
     // Rewrite the previous WHILE loop as a DO..WHILE loop.
200
     // Rewrite the previous WHILE loop as a DO..WHILE loop.
167
     // Notice how the “runningScore” variable usage is different.
201
     // Notice how the “runningScore” variable usage is different.
168
     public boolean checkGameScoreDoWhile() {
202
     public boolean checkGameScoreDoWhile() {
169
         int w = 0;
203
         int w = 0;
170
-        int highestScore = 236;
204
+        int highestScore = 236; 
171
         int currentScore = gameNextScore();
205
         int currentScore = gameNextScore();
172
         int runningScore = 0;
206
         int runningScore = 0;
173
 
207
 
174
         // do your while loop here
208
         // do your while loop here
175
-
176
-            // calling
209
+        do {
210
+            currentScore += runningScore;
211
+            currentScore += gameNextScore();
177
             w = w + 1;
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
         return w >= 3;
218
         return w >= 3;
181
     }
219
     }
187
     public int checkServerStatus() {
225
     public int checkServerStatus() {
188
         int w = 0;
226
         int w = 0;
189
         String adminPhoneNumber = "+1 202 456 1111";
227
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
191
 
228
 
192
         // calling
229
         // calling
193
         w = w + 1;
230
         w = w + 1;
194
         // each time through the inner loop
231
         // each time through the inner loop
195
-        
232
+
196
         return w;
233
         return w;
197
     }
234
     }
198
 
235
 
201
     // and if it is, add 7 to “i”
238
     // and if it is, add 7 to “i”
202
     public int loop50by7() {
239
     public int loop50by7() {
203
         int w = 0;
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
         return w;
250
         return w;
211
     }
251
     }
212
 
252
 
239
         int w = 0;
279
         int w = 0;
240
         int sumOfThrees = 0;
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
         System.out.print("The Sum is ");
286
         System.out.print("The Sum is ");
248
         System.out.println(sumOfThrees);
287
         System.out.println(sumOfThrees);
249
 
288
 
256
         int w = 0;
295
         int w = 0;
257
         int sumOfThrees = 0;
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
         System.out.print("The Sum is ");
302
         System.out.print("The Sum is ");
265
         System.out.println(sumOfThrees);
303
         System.out.println(sumOfThrees);
266
 
304
 
279
         boolean onTime = true;
317
         boolean onTime = true;
280
 
318
 
281
         // ADD YOUR CODE here.
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
         return w;
325
         return w;
288
     }
326
     }
289
 
327
 
296
         int w = 0;
334
         int w = 0;
297
         int numberOfVotes = voteTallies.length;
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
         return w;
341
         return w;
305
     }
342
     }
306
 
343
 
311
         int w = 0;
348
         int w = 0;
312
         int numberOfVotes = voteTallies.length;
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
         return w;
355
         return w;
320
     }
356
     }
321
 
357
 
378
     //         return (i >= 3);
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
     private void sendEmergencyText(String mesg, String phone) {
426
     private void sendEmergencyText(String mesg, String phone) {
390
     }
427
     }
391
 
428
 

+ 11
- 11
package.bluej View File

7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
 editor.fx.0.height=722
8
 editor.fx.0.height=722
9
 editor.fx.0.width=800
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
 package.divider.horizontal=0.6
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
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4
24
 package.showExtends=true
24
 package.showExtends=true