|
@@ -19,11 +19,15 @@ public class WriteLoops {
|
19
|
19
|
int w = 0;
|
20
|
20
|
|
21
|
21
|
// Write a FOR loop that counts from 1 to 10.
|
22
|
|
- // calling
|
23
|
|
- w = w + 1;
|
24
|
|
- // each time through the loop
|
|
22
|
+ // calling
|
|
23
|
+ //w = w + 1;
|
|
24
|
+ // each time through the loop
|
25
|
25
|
|
26
|
26
|
// this will tell the test how many times the loop executed.
|
|
27
|
+ for (int i = 1; i <= 5; i++) {
|
|
28
|
+ w = w + 1;
|
|
29
|
+ }
|
|
30
|
+
|
27
|
31
|
return w;
|
28
|
32
|
}
|
29
|
33
|
|
|
@@ -32,9 +36,12 @@ public class WriteLoops {
|
32
|
36
|
|
33
|
37
|
// Write a FOR loop that counts from 1 to 10.
|
34
|
38
|
// calling
|
35
|
|
- w = w + 1;
|
|
39
|
+ //w = w + 1;
|
36
|
40
|
// each time through the loop
|
37
|
|
-
|
|
41
|
+ for (int i = 0; i<= 9; i++) {
|
|
42
|
+ w = w + 1;
|
|
43
|
+ }
|
|
44
|
+
|
38
|
45
|
return w;
|
39
|
46
|
}
|
40
|
47
|
|
|
@@ -43,9 +50,12 @@ public class WriteLoops {
|
43
|
50
|
|
44
|
51
|
// Write a FOR loop that makes 10 iterations, start at 21.
|
45
|
52
|
// calling
|
46
|
|
- w = w + 1;
|
|
53
|
+ //w = w + 1;
|
47
|
54
|
// each time through the loop
|
48
|
|
-
|
|
55
|
+ for(int i = 21; i <= 31; i++) {
|
|
56
|
+ w = w + 1;
|
|
57
|
+ }
|
|
58
|
+
|
49
|
59
|
return w;
|
50
|
60
|
}
|
51
|
61
|
|
|
@@ -54,9 +64,12 @@ public class WriteLoops {
|
54
|
64
|
|
55
|
65
|
// Write a FOR loop that counts down from 100 to 0.
|
56
|
66
|
// calling
|
57
|
|
- w = w + 1;
|
|
67
|
+ //w = w + 1;
|
58
|
68
|
// each time through the loop
|
59
|
|
-
|
|
69
|
+ for(int i = 100; i > 0; i--) {
|
|
70
|
+ w = w + 1;
|
|
71
|
+ }
|
|
72
|
+
|
60
|
73
|
return w;
|
61
|
74
|
}
|
62
|
75
|
|
|
@@ -65,8 +78,12 @@ public class WriteLoops {
|
65
|
78
|
|
66
|
79
|
// Write a FOR loop from 0 to 32 by 2s.
|
67
|
80
|
// calling
|
68
|
|
- w = w + 1;
|
|
81
|
+ //w = w + 1;
|
69
|
82
|
// each time through the loop
|
|
83
|
+
|
|
84
|
+ for (int i = 32; i <= 0; i+=2) {
|
|
85
|
+ w = w + 1;
|
|
86
|
+ }
|
70
|
87
|
return w;
|
71
|
88
|
}
|
72
|
89
|
|
|
@@ -75,9 +92,13 @@ public class WriteLoops {
|
75
|
92
|
|
76
|
93
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
77
|
94
|
// calling
|
78
|
|
- w = w + 1;
|
|
95
|
+ //w = w + 1;
|
79
|
96
|
// each time through the loop
|
80
|
|
-
|
|
97
|
+
|
|
98
|
+ for(int i = 1; i <5001; i+=11) {
|
|
99
|
+ w = w + 1;
|
|
100
|
+ }
|
|
101
|
+
|
81
|
102
|
return w;
|
82
|
103
|
}
|
83
|
104
|
|
|
@@ -86,9 +107,16 @@ public class WriteLoops {
|
86
|
107
|
|
87
|
108
|
// Write a nested FOR loop(s), where one counts from
|
88
|
109
|
// 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
|
|
110
|
+ // calling
|
|
111
|
+ //w = w + 1;
|
|
112
|
+ // each time through the inner loop
|
|
113
|
+
|
|
114
|
+ for(w = 0; w < 100;) {
|
|
115
|
+ w = w + 1;
|
|
116
|
+ for(int j = w; j <= 4;) {
|
|
117
|
+ j+=j;
|
|
118
|
+ }
|
|
119
|
+ }
|
92
|
120
|
|
93
|
121
|
return w;
|
94
|
122
|
}
|
|
@@ -101,10 +129,16 @@ public class WriteLoops {
|
101
|
129
|
// loop index counter and if it’s greater than 51,
|
102
|
130
|
// prints “Hello Zipcode” instead of the statement w = w + 1;
|
103
|
131
|
|
104
|
|
- // calling
|
|
132
|
+ // calling
|
|
133
|
+ //w = w + 1;
|
|
134
|
+ // each time through the inner loop
|
|
135
|
+ for (int i = 5; i <=105; i++) {
|
|
136
|
+
|
|
137
|
+ if(i > 58) {
|
105
|
138
|
w = w + 1;
|
106
|
|
- // each time through the inner loop
|
107
|
|
-
|
|
139
|
+ }
|
|
140
|
+ }
|
|
141
|
+
|
108
|
142
|
return w;
|
109
|
143
|
}
|
110
|
144
|
|
|
@@ -133,13 +167,17 @@ public class WriteLoops {
|
133
|
167
|
int w = 0;
|
134
|
168
|
|
135
|
169
|
// you need to use a .equals for two Strings.
|
|
170
|
+ while(gpsCurrentLocation().equals("Not Home")){
|
|
171
|
+ if(gpsCurrentLocation().equals("Not Home")){
|
|
172
|
+ driveSomeMore();
|
|
173
|
+ // calling
|
|
174
|
+ w += 1;
|
|
175
|
+ // each time through the inner loop
|
136
|
176
|
|
137
|
|
- // calling
|
138
|
|
- w = w + 1;
|
139
|
|
- // each time through the inner loop
|
140
|
|
-
|
141
|
|
-
|
142
|
|
- return w;
|
|
177
|
+ }
|
|
178
|
+ }
|
|
179
|
+ System.out.println("Honey I'm Home");
|
|
180
|
+ return w;
|
143
|
181
|
}
|
144
|
182
|
|
145
|
183
|
// Getting harder...
|
|
@@ -149,35 +187,50 @@ public class WriteLoops {
|
149
|
187
|
// "runningScore"
|
150
|
188
|
// and then sets “currentScore” to “gameNextScore()”
|
151
|
189
|
public int checkGameScore() {
|
152
|
|
- int w = 0;
|
153
|
|
- int highestScore = 236;
|
|
190
|
+ int w = 1;
|
|
191
|
+ int highestScore = 235;
|
154
|
192
|
int currentScore = gameNextScore();
|
155
|
193
|
int runningScore = 0;
|
156
|
194
|
|
157
|
|
- // do your while loop here
|
158
|
|
-
|
159
|
|
- // calling
|
|
195
|
+ while (runningScore < highestScore){
|
|
196
|
+ runningScore += currentScore;
|
|
197
|
+ currentScore += gameNextScore();
|
|
198
|
+
|
160
|
199
|
w = w + 1;
|
161
|
|
- // each time through the inner loop
|
162
|
|
-
|
|
200
|
+
|
|
201
|
+ }
|
|
202
|
+ // do your while loop here
|
|
203
|
+
|
|
204
|
+ // calling
|
|
205
|
+ // w = w + 1;
|
|
206
|
+ // each time through the inner loop
|
|
207
|
+
|
163
|
208
|
return w; // >= 3;
|
164
|
|
- }
|
165
|
209
|
|
|
210
|
+ }
|
166
|
211
|
// Rewrite the previous WHILE loop as a DO..WHILE loop.
|
167
|
212
|
// Notice how the “runningScore” variable usage is different.
|
168
|
213
|
public boolean checkGameScoreDoWhile() {
|
169
|
214
|
int w = 0;
|
170
|
|
- int highestScore = 236;
|
|
215
|
+ int highestScore = 235;
|
171
|
216
|
int currentScore = gameNextScore();
|
172
|
217
|
int runningScore = 0;
|
|
218
|
+ boolean score;
|
|
219
|
+
|
|
220
|
+ do{ score=true;
|
|
221
|
+ runningScore += currentScore;
|
|
222
|
+ currentScore += gameNextScore();
|
|
223
|
+ w = w + 1;
|
|
224
|
+
|
|
225
|
+ }while(runningScore < runningScore);
|
173
|
226
|
|
174
|
227
|
// do your while loop here
|
175
|
228
|
|
176
|
|
- // calling
|
177
|
|
- w = w + 1;
|
178
|
|
- // each time through the inner loop
|
|
229
|
+ // calling
|
|
230
|
+ // w = w + 1;
|
|
231
|
+ // each time through the inner loop
|
179
|
232
|
|
180
|
|
- return w >= 3;
|
|
233
|
+ return score;
|
181
|
234
|
}
|
182
|
235
|
|
183
|
236
|
// Write a WHILE loop that checks “serverIsRunning()” and if true
|
|
@@ -187,12 +240,18 @@ public class WriteLoops {
|
187
|
240
|
public int checkServerStatus() {
|
188
|
241
|
int w = 0;
|
189
|
242
|
String adminPhoneNumber = "+1 202 456 1111";
|
190
|
|
-
|
|
243
|
+ while (serverIsRunning()) {
|
|
244
|
+ if (serverIsRunning()==true) {
|
|
245
|
+ waitFor(5);
|
|
246
|
+ } else {
|
|
247
|
+ sendEmergencyText("Help!",adminPhoneNumber);
|
|
248
|
+ tryServerRestart("","");
|
|
249
|
+ }
|
191
|
250
|
|
192
|
|
- // calling
|
193
|
|
- w = w + 1;
|
194
|
|
- // each time through the inner loop
|
195
|
|
-
|
|
251
|
+ // calling
|
|
252
|
+ w = w + 1;
|
|
253
|
+ // each time through the inner loop
|
|
254
|
+ }
|
196
|
255
|
return w;
|
197
|
256
|
}
|
198
|
257
|
|
|
@@ -202,11 +261,10 @@ public class WriteLoops {
|
202
|
261
|
public int loop50by7() {
|
203
|
262
|
int w = 0;
|
204
|
263
|
|
|
264
|
+ // calling
|
|
265
|
+ w = w + 1;
|
|
266
|
+ // each time through the inner loop
|
205
|
267
|
|
206
|
|
- // calling
|
207
|
|
- w = w + 1;
|
208
|
|
- // each time through the inner loop
|
209
|
|
-
|
210
|
268
|
return w;
|
211
|
269
|
}
|
212
|
270
|
|
|
@@ -239,11 +297,10 @@ public class WriteLoops {
|
239
|
297
|
int w = 0;
|
240
|
298
|
int sumOfThrees = 0;
|
241
|
299
|
|
242
|
|
-
|
243
|
|
- // calling
|
244
|
|
- w = w + 1;
|
245
|
|
- // each time through the inner loop
|
246
|
|
-
|
|
300
|
+ // calling
|
|
301
|
+ w = w + 1;
|
|
302
|
+ // each time through the inner loop
|
|
303
|
+
|
247
|
304
|
System.out.print("The Sum is ");
|
248
|
305
|
System.out.println(sumOfThrees);
|
249
|
306
|
|
|
@@ -256,11 +313,10 @@ public class WriteLoops {
|
256
|
313
|
int w = 0;
|
257
|
314
|
int sumOfThrees = 0;
|
258
|
315
|
|
259
|
|
-
|
260
|
|
- // calling
|
261
|
|
- w = w + 1;
|
262
|
|
- // each time through the inner loop
|
263
|
|
-
|
|
316
|
+ // calling
|
|
317
|
+ w = w + 1;
|
|
318
|
+ // each time through the inner loop
|
|
319
|
+
|
264
|
320
|
System.out.print("The Sum is ");
|
265
|
321
|
System.out.println(sumOfThrees);
|
266
|
322
|
|
|
@@ -279,11 +335,11 @@ public class WriteLoops {
|
279
|
335
|
boolean onTime = true;
|
280
|
336
|
|
281
|
337
|
// ADD YOUR CODE here.
|
282
|
|
-
|
283
|
|
- // be sure to call
|
284
|
|
- w = w + 1;
|
285
|
|
- // each time inside the loop
|
286
|
|
-
|
|
338
|
+
|
|
339
|
+ // be sure to call
|
|
340
|
+ w = w + 1;
|
|
341
|
+ // each time inside the loop
|
|
342
|
+
|
287
|
343
|
return w;
|
288
|
344
|
}
|
289
|
345
|
|
|
@@ -296,11 +352,10 @@ public class WriteLoops {
|
296
|
352
|
int w = 0;
|
297
|
353
|
int numberOfVotes = voteTallies.length;
|
298
|
354
|
|
299
|
|
-
|
300
|
|
- // calling
|
301
|
|
- w = w + 1;
|
302
|
|
- // each time through the inner loop
|
303
|
|
-
|
|
355
|
+ // calling
|
|
356
|
+ w = w + 1;
|
|
357
|
+ // each time through the inner loop
|
|
358
|
+
|
304
|
359
|
return w;
|
305
|
360
|
}
|
306
|
361
|
|
|
@@ -311,11 +366,10 @@ public class WriteLoops {
|
311
|
366
|
int w = 0;
|
312
|
367
|
int numberOfVotes = voteTallies.length;
|
313
|
368
|
|
|
369
|
+ // calling
|
|
370
|
+ w = w + 1;
|
|
371
|
+ // each time through the inner loop
|
314
|
372
|
|
315
|
|
- // calling
|
316
|
|
- w = w + 1;
|
317
|
|
- // each time through the inner loop
|
318
|
|
-
|
319
|
373
|
return w;
|
320
|
374
|
}
|
321
|
375
|
|
|
@@ -378,14 +432,15 @@ public class WriteLoops {
|
378
|
432
|
// return (i >= 3);
|
379
|
433
|
// };
|
380
|
434
|
// };
|
381
|
|
- private int summer = 0;
|
382
|
|
- private boolean isSummer() {
|
383
|
|
- if (summer == 3) {
|
384
|
|
- return true;
|
385
|
|
- }
|
386
|
|
- summer++;
|
387
|
|
- return false;
|
|
435
|
+ private int summer = 0;
|
|
436
|
+ private boolean isSummer() {
|
|
437
|
+ if (summer == 3) {
|
|
438
|
+ return true;
|
388
|
439
|
}
|
|
440
|
+ summer++;
|
|
441
|
+ return false;
|
|
442
|
+ }
|
|
443
|
+
|
389
|
444
|
private void sendEmergencyText(String mesg, String phone) {
|
390
|
445
|
}
|
391
|
446
|
|