|
|
@@ -1,5 +1,4 @@
|
|
1
|
1
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
|
2
|
|
-
|
|
3
|
2
|
import java.awt.SystemTray;
|
|
4
|
3
|
import java.util.concurrent.ThreadLocalRandom;
|
|
5
|
4
|
import java.util.function.Supplier;
|
|
|
@@ -19,11 +18,16 @@ public class WriteLoops {
|
|
19
|
18
|
int w = 0;
|
|
20
|
19
|
|
|
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
|
+ w = w + 1;
|
|
|
23
|
+ // each time through the loop
|
|
25
|
24
|
|
|
26
|
25
|
// this will tell the test how many times the loop executed.
|
|
|
26
|
+
|
|
|
27
|
+ for (int i = 1; i < 5; i ++)
|
|
|
28
|
+ {
|
|
|
29
|
+ w = w+1;
|
|
|
30
|
+ }
|
|
27
|
31
|
return w;
|
|
28
|
32
|
}
|
|
29
|
33
|
|
|
|
@@ -34,7 +38,11 @@ public class WriteLoops {
|
|
34
|
38
|
// calling
|
|
35
|
39
|
w = w + 1;
|
|
36
|
40
|
// each time through the loop
|
|
37
|
|
-
|
|
|
41
|
+
|
|
|
42
|
+ for(int i = 1; i < 10; i ++){
|
|
|
43
|
+ w = w + 1;
|
|
|
44
|
+ }
|
|
|
45
|
+
|
|
38
|
46
|
return w;
|
|
39
|
47
|
}
|
|
40
|
48
|
|
|
|
@@ -43,9 +51,12 @@ public class WriteLoops {
|
|
43
|
51
|
|
|
44
|
52
|
// Write a FOR loop that makes 10 iterations, start at 21.
|
|
45
|
53
|
// calling
|
|
46
|
|
- w = w + 1;
|
|
|
54
|
+ for(int i = 21; i < 32; i ++)
|
|
|
55
|
+ {
|
|
|
56
|
+ w = w + 1;
|
|
|
57
|
+ }
|
|
47
|
58
|
// each time through the loop
|
|
48
|
|
-
|
|
|
59
|
+
|
|
49
|
60
|
return w;
|
|
50
|
61
|
}
|
|
51
|
62
|
|
|
|
@@ -54,30 +65,29 @@ public class WriteLoops {
|
|
54
|
65
|
|
|
55
|
66
|
// Write a FOR loop that counts down from 100 to 0.
|
|
56
|
67
|
// calling
|
|
57
|
|
- w = w + 1;
|
|
58
|
|
- // each time through the loop
|
|
59
|
|
-
|
|
|
68
|
+ for(int i = 0; i < 100; i ++){
|
|
|
69
|
+ w = w + 1;
|
|
|
70
|
+ // each time through the loop
|
|
|
71
|
+ }
|
|
60
|
72
|
return w;
|
|
61
|
73
|
}
|
|
62
|
74
|
|
|
63
|
75
|
public int byTwoTo32() {
|
|
64
|
76
|
int w = 0;
|
|
65
|
|
-
|
|
66
|
|
- // Write a FOR loop from 0 to 32 by 2s.
|
|
67
|
|
- // calling
|
|
68
|
|
- w = w + 1;
|
|
69
|
|
- // each time through the loop
|
|
|
77
|
+ for(int i = 0; i < 32; i += 2)
|
|
|
78
|
+ {
|
|
|
79
|
+ //w = w + 1;
|
|
|
80
|
+ }
|
|
70
|
81
|
return w;
|
|
71
|
82
|
}
|
|
72
|
83
|
|
|
73
|
84
|
public int countDownFrom5000() {
|
|
74
|
85
|
int w = 0;
|
|
|
86
|
+ for(int i = 1; i < 5001; i += 11)
|
|
|
87
|
+ {
|
|
|
88
|
+ w = w + 1;
|
|
|
89
|
+ }
|
|
75
|
90
|
|
|
76
|
|
- // Write a FOR loop from 1 to less than 5001 by 11s.
|
|
77
|
|
- // calling
|
|
78
|
|
- w = w + 1;
|
|
79
|
|
- // each time through the loop
|
|
80
|
|
-
|
|
81
|
91
|
return w;
|
|
82
|
92
|
}
|
|
83
|
93
|
|
|
|
@@ -86,10 +96,17 @@ 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
|
+ //w = w + 1;
|
|
|
101
|
+ // each time through the inner loop
|
|
92
|
102
|
|
|
|
103
|
+ for(int i = 0; i < 20; i ++)
|
|
|
104
|
+ {
|
|
|
105
|
+ for(int j = 0; j <= 4; j ++)
|
|
|
106
|
+ {
|
|
|
107
|
+ w = w + 1;
|
|
|
108
|
+ }
|
|
|
109
|
+ }
|
|
93
|
110
|
return w;
|
|
94
|
111
|
}
|
|
95
|
112
|
|
|
|
@@ -101,10 +118,20 @@ public class WriteLoops {
|
|
101
|
118
|
// loop index counter and if it’s greater than 51,
|
|
102
|
119
|
// prints “Hello Zipcode” instead of the statement w = w + 1;
|
|
103
|
120
|
|
|
104
|
|
- // calling
|
|
|
121
|
+ // calling
|
|
|
122
|
+
|
|
|
123
|
+ // each time through the inner loop
|
|
|
124
|
+
|
|
|
125
|
+ for(int i = 5; i < 105; i ++)
|
|
|
126
|
+ {
|
|
|
127
|
+ if(i > 51)
|
|
|
128
|
+ {
|
|
|
129
|
+ System.out.println("Hello Zipcode");
|
|
|
130
|
+ } else {
|
|
105
|
131
|
w = w + 1;
|
|
106
|
|
- // each time through the inner loop
|
|
107
|
|
-
|
|
|
132
|
+ }
|
|
|
133
|
+ }
|
|
|
134
|
+
|
|
108
|
135
|
return w;
|
|
109
|
136
|
}
|
|
110
|
137
|
|
|
|
@@ -133,13 +160,16 @@ public class WriteLoops {
|
|
133
|
160
|
int w = 0;
|
|
134
|
161
|
|
|
135
|
162
|
// you need to use a .equals for two Strings.
|
|
136
|
|
-
|
|
|
163
|
+ while(!gpsCurrentLocation().equals("Home"))
|
|
|
164
|
+ {
|
|
137
|
165
|
// calling
|
|
138
|
166
|
w = w + 1;
|
|
139
|
167
|
// each time through the inner loop
|
|
140
|
|
-
|
|
|
168
|
+ driveSomeMore();
|
|
141
|
169
|
|
|
142
|
|
- return w;
|
|
|
170
|
+ }
|
|
|
171
|
+ System.out.println("Honey, I'm Home!");
|
|
|
172
|
+ return w;
|
|
143
|
173
|
}
|
|
144
|
174
|
|
|
145
|
175
|
// Getting harder...
|
|
|
@@ -149,17 +179,21 @@ public class WriteLoops {
|
|
149
|
179
|
// "runningScore"
|
|
150
|
180
|
// and then sets “currentScore” to “gameNextScore()”
|
|
151
|
181
|
public int checkGameScore() {
|
|
152
|
|
- int w = 0;
|
|
153
|
|
- int highestScore = 236;
|
|
154
|
|
- int currentScore = gameNextScore();
|
|
155
|
|
- int runningScore = 0;
|
|
|
182
|
+ int w = 0;
|
|
|
183
|
+ int highestScore = 236;
|
|
|
184
|
+ int currentScore = gameNextScore();
|
|
|
185
|
+ int runningScore = 0;
|
|
156
|
186
|
|
|
157
|
187
|
// do your while loop here
|
|
158
|
|
-
|
|
159
|
|
- // calling
|
|
|
188
|
+ while(runningScore < highestScore){
|
|
|
189
|
+ if(runningScore < highestScore)
|
|
|
190
|
+ {
|
|
|
191
|
+ runningScore += currentScore;
|
|
160
|
192
|
w = w + 1;
|
|
161
|
|
- // each time through the inner loop
|
|
|
193
|
+ }
|
|
|
194
|
+ currentScore = gameNextScore();
|
|
162
|
195
|
|
|
|
196
|
+ }
|
|
163
|
197
|
return w; // >= 3;
|
|
164
|
198
|
}
|
|
165
|
199
|
|
|
|
@@ -171,12 +205,14 @@ public class WriteLoops {
|
|
171
|
205
|
int currentScore = gameNextScore();
|
|
172
|
206
|
int runningScore = 0;
|
|
173
|
207
|
|
|
174
|
|
- // do your while loop here
|
|
175
|
|
-
|
|
176
|
|
- // calling
|
|
177
|
|
- w = w + 1;
|
|
178
|
|
- // each time through the inner loop
|
|
179
|
|
-
|
|
|
208
|
+ do {
|
|
|
209
|
+ if(runningScore < highestScore)
|
|
|
210
|
+ {
|
|
|
211
|
+ runningScore += currentScore;
|
|
|
212
|
+ w = w + 1;
|
|
|
213
|
+ }
|
|
|
214
|
+ currentScore = gameNextScore();
|
|
|
215
|
+ }while(runningScore < highestScore);
|
|
180
|
216
|
return w >= 3;
|
|
181
|
217
|
}
|
|
182
|
218
|
|
|
|
@@ -187,12 +223,19 @@ public class WriteLoops {
|
|
187
|
223
|
public int checkServerStatus() {
|
|
188
|
224
|
int w = 0;
|
|
189
|
225
|
String adminPhoneNumber = "+1 202 456 1111";
|
|
|
226
|
+ while(serverIsRunning())
|
|
|
227
|
+ {
|
|
|
228
|
+ if(serverIsRunning() == true)
|
|
|
229
|
+ {
|
|
|
230
|
+ waitFor(5);
|
|
|
231
|
+ }
|
|
|
232
|
+ w = w + 1;
|
|
|
233
|
+ }
|
|
190
|
234
|
|
|
191
|
|
-
|
|
192
|
|
- // calling
|
|
193
|
|
- w = w + 1;
|
|
194
|
|
- // each time through the inner loop
|
|
195
|
|
-
|
|
|
235
|
+ if(serverIsRunning() == false){
|
|
|
236
|
+ sendEmergencyText("Help", adminPhoneNumber);
|
|
|
237
|
+ tryServerRestart("Help", adminPhoneNumber);
|
|
|
238
|
+ }
|
|
196
|
239
|
return w;
|
|
197
|
240
|
}
|
|
198
|
241
|
|
|
|
@@ -201,12 +244,16 @@ public class WriteLoops {
|
|
201
|
244
|
// and if it is, add 7 to “i”
|
|
202
|
245
|
public int loop50by7() {
|
|
203
|
246
|
int w = 0;
|
|
204
|
|
-
|
|
205
|
|
-
|
|
206
|
|
- // calling
|
|
|
247
|
+ int i = 7;
|
|
|
248
|
+ while(i < 50){
|
|
|
249
|
+ i += 7;
|
|
207
|
250
|
w = w + 1;
|
|
208
|
|
- // each time through the inner loop
|
|
|
251
|
+ }
|
|
|
252
|
+
|
|
|
253
|
+ // calling
|
|
209
|
254
|
|
|
|
255
|
+ // each time through the inner loop
|
|
|
256
|
+
|
|
210
|
257
|
return w;
|
|
211
|
258
|
}
|
|
212
|
259
|
|
|
|
@@ -239,11 +286,10 @@ public class WriteLoops {
|
|
239
|
286
|
int w = 0;
|
|
240
|
287
|
int sumOfThrees = 0;
|
|
241
|
288
|
|
|
242
|
|
-
|
|
243
|
|
- // calling
|
|
244
|
|
- w = w + 1;
|
|
245
|
|
- // each time through the inner loop
|
|
246
|
|
-
|
|
|
289
|
+ // calling
|
|
|
290
|
+ w = w + 1;
|
|
|
291
|
+ // each time through the inner loop
|
|
|
292
|
+
|
|
247
|
293
|
System.out.print("The Sum is ");
|
|
248
|
294
|
System.out.println(sumOfThrees);
|
|
249
|
295
|
|
|
|
@@ -256,11 +302,10 @@ public class WriteLoops {
|
|
256
|
302
|
int w = 0;
|
|
257
|
303
|
int sumOfThrees = 0;
|
|
258
|
304
|
|
|
259
|
|
-
|
|
260
|
|
- // calling
|
|
261
|
|
- w = w + 1;
|
|
262
|
|
- // each time through the inner loop
|
|
263
|
|
-
|
|
|
305
|
+ // calling
|
|
|
306
|
+ w = w + 1;
|
|
|
307
|
+ // each time through the inner loop
|
|
|
308
|
+
|
|
264
|
309
|
System.out.print("The Sum is ");
|
|
265
|
310
|
System.out.println(sumOfThrees);
|
|
266
|
311
|
|
|
|
@@ -279,11 +324,11 @@ public class WriteLoops {
|
|
279
|
324
|
boolean onTime = true;
|
|
280
|
325
|
|
|
281
|
326
|
// ADD YOUR CODE here.
|
|
282
|
|
-
|
|
283
|
|
- // be sure to call
|
|
284
|
|
- w = w + 1;
|
|
285
|
|
- // each time inside the loop
|
|
286
|
|
-
|
|
|
327
|
+
|
|
|
328
|
+ // be sure to call
|
|
|
329
|
+ w = w + 1;
|
|
|
330
|
+ // each time inside the loop
|
|
|
331
|
+
|
|
287
|
332
|
return w;
|
|
288
|
333
|
}
|
|
289
|
334
|
|
|
|
@@ -296,11 +341,10 @@ public class WriteLoops {
|
|
296
|
341
|
int w = 0;
|
|
297
|
342
|
int numberOfVotes = voteTallies.length;
|
|
298
|
343
|
|
|
299
|
|
-
|
|
300
|
|
- // calling
|
|
301
|
|
- w = w + 1;
|
|
302
|
|
- // each time through the inner loop
|
|
303
|
|
-
|
|
|
344
|
+ // calling
|
|
|
345
|
+ w = w + 1;
|
|
|
346
|
+ // each time through the inner loop
|
|
|
347
|
+
|
|
304
|
348
|
return w;
|
|
305
|
349
|
}
|
|
306
|
350
|
|
|
|
@@ -311,11 +355,10 @@ public class WriteLoops {
|
|
311
|
355
|
int w = 0;
|
|
312
|
356
|
int numberOfVotes = voteTallies.length;
|
|
313
|
357
|
|
|
|
358
|
+ // calling
|
|
|
359
|
+ w = w + 1;
|
|
|
360
|
+ // each time through the inner loop
|
|
314
|
361
|
|
|
315
|
|
- // calling
|
|
316
|
|
- w = w + 1;
|
|
317
|
|
- // each time through the inner loop
|
|
318
|
|
-
|
|
319
|
362
|
return w;
|
|
320
|
363
|
}
|
|
321
|
364
|
|
|
|
@@ -378,14 +421,15 @@ public class WriteLoops {
|
|
378
|
421
|
// return (i >= 3);
|
|
379
|
422
|
// };
|
|
380
|
423
|
// };
|
|
381
|
|
- private int summer = 0;
|
|
382
|
|
- private boolean isSummer() {
|
|
383
|
|
- if (summer == 3) {
|
|
384
|
|
- return true;
|
|
385
|
|
- }
|
|
386
|
|
- summer++;
|
|
387
|
|
- return false;
|
|
|
424
|
+ private int summer = 0;
|
|
|
425
|
+ private boolean isSummer() {
|
|
|
426
|
+ if (summer == 3) {
|
|
|
427
|
+ return true;
|
|
388
|
428
|
}
|
|
|
429
|
+ summer++;
|
|
|
430
|
+ return false;
|
|
|
431
|
+ }
|
|
|
432
|
+
|
|
389
|
433
|
private void sendEmergencyText(String mesg, String phone) {
|
|
390
|
434
|
}
|
|
391
|
435
|
|