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