|
@@ -19,9 +19,12 @@ 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
|
+ for(int i=1;i<=5;i++){
|
|
26
|
+ w +=1;
|
|
27
|
+ }
|
25
|
28
|
|
26
|
29
|
// this will tell the test how many times the loop executed.
|
27
|
30
|
return w;
|
|
@@ -32,9 +35,12 @@ public class WriteLoops {
|
32
|
35
|
|
33
|
36
|
// Write a FOR loop that counts from 1 to 10.
|
34
|
37
|
// calling
|
35
|
|
- w = w + 1;
|
|
38
|
+ //w = w + 1;
|
36
|
39
|
// each time through the loop
|
37
|
|
-
|
|
40
|
+ for(int i=1;i<=10;i++){
|
|
41
|
+ w +=1;
|
|
42
|
+ }
|
|
43
|
+
|
38
|
44
|
return w;
|
39
|
45
|
}
|
40
|
46
|
|
|
@@ -45,7 +51,10 @@ public class WriteLoops {
|
45
|
51
|
// calling
|
46
|
52
|
w = w + 1;
|
47
|
53
|
// each time through the loop
|
48
|
|
-
|
|
54
|
+ for(int i=21;i<=30;i++){
|
|
55
|
+ w +=1;
|
|
56
|
+ }
|
|
57
|
+
|
49
|
58
|
return w;
|
50
|
59
|
}
|
51
|
60
|
|
|
@@ -56,7 +65,10 @@ public class WriteLoops {
|
56
|
65
|
// calling
|
57
|
66
|
w = w + 1;
|
58
|
67
|
// each time through the loop
|
59
|
|
-
|
|
68
|
+ for(int i=99;i>=1;i--){
|
|
69
|
+ w +=1;
|
|
70
|
+ }
|
|
71
|
+
|
60
|
72
|
return w;
|
61
|
73
|
}
|
62
|
74
|
|
|
@@ -65,8 +77,11 @@ public class WriteLoops {
|
65
|
77
|
|
66
|
78
|
// Write a FOR loop from 0 to 32 by 2s.
|
67
|
79
|
// calling
|
68
|
|
- w = w + 1;
|
|
80
|
+ //w = w + 1;
|
69
|
81
|
// each time through the loop
|
|
82
|
+ for (int i=1;i<=32;i+=2){
|
|
83
|
+ w +=0;
|
|
84
|
+ }
|
70
|
85
|
return w;
|
71
|
86
|
}
|
72
|
87
|
|
|
@@ -75,9 +90,13 @@ public class WriteLoops {
|
75
|
90
|
|
76
|
91
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
77
|
92
|
// calling
|
78
|
|
- w = w + 1;
|
|
93
|
+ //w = w + 1;
|
79
|
94
|
// each time through the loop
|
80
|
|
-
|
|
95
|
+ int i = 0;
|
|
96
|
+ for(i=1;i<5000;i+=11){
|
|
97
|
+ w +=1;
|
|
98
|
+ }
|
|
99
|
+
|
81
|
100
|
return w;
|
82
|
101
|
}
|
83
|
102
|
|
|
@@ -86,10 +105,18 @@ public class WriteLoops {
|
86
|
105
|
|
87
|
106
|
// Write a nested FOR loop(s), where one counts from
|
88
|
107
|
// 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
|
|
108
|
+ // calling
|
|
109
|
+ //w = w + 1;
|
|
110
|
+ // each time through the inner loop
|
|
111
|
+ int i =0;
|
|
112
|
+ for(i=0;i<20;i++){
|
|
113
|
+ int j = 0;
|
|
114
|
+ for(j=0;j<=4;j++){
|
|
115
|
+ w +=1;
|
|
116
|
+
|
|
117
|
+ }
|
92
|
118
|
|
|
119
|
+ }
|
93
|
120
|
return w;
|
94
|
121
|
}
|
95
|
122
|
|
|
@@ -101,10 +128,20 @@ public class WriteLoops {
|
101
|
128
|
// loop index counter and if it’s greater than 51,
|
102
|
129
|
// prints “Hello Zipcode” instead of the statement w = w + 1;
|
103
|
130
|
|
104
|
|
- // calling
|
105
|
|
- w = w + 1;
|
106
|
|
- // each time through the inner loop
|
107
|
|
-
|
|
131
|
+ // calling
|
|
132
|
+ //w = w + 1;
|
|
133
|
+ // each time through the inner loop
|
|
134
|
+ int i = 0;
|
|
135
|
+ for (i=5;i<=105;i++){
|
|
136
|
+ System.out.println(w);
|
|
137
|
+ if (i>51){
|
|
138
|
+ System.out.println("Hello Zipcode");
|
|
139
|
+ }
|
|
140
|
+ else{
|
|
141
|
+ w +=1;
|
|
142
|
+ }
|
|
143
|
+ }
|
|
144
|
+
|
108
|
145
|
return w;
|
109
|
146
|
}
|
110
|
147
|
|
|
@@ -134,12 +171,16 @@ public class WriteLoops {
|
134
|
171
|
|
135
|
172
|
// you need to use a .equals for two Strings.
|
136
|
173
|
|
137
|
|
- // calling
|
|
174
|
+ // calling
|
|
175
|
+ //w = w + 1;
|
|
176
|
+ // each time through the inner loop
|
|
177
|
+ while(!gpsCurrentLocation().equals("Home")){
|
138
|
178
|
w = w + 1;
|
139
|
|
- // each time through the inner loop
|
140
|
|
-
|
|
179
|
+ driveSomeMore();
|
|
180
|
+ }
|
|
181
|
+ System.out.println("Honey, I'm home");
|
141
|
182
|
|
142
|
|
- return w;
|
|
183
|
+ return w;
|
143
|
184
|
}
|
144
|
185
|
|
145
|
186
|
// Getting harder...
|
|
@@ -155,11 +196,15 @@ public class WriteLoops {
|
155
|
196
|
int runningScore = 0;
|
156
|
197
|
|
157
|
198
|
// do your while loop here
|
158
|
|
-
|
159
|
|
- // calling
|
160
|
|
- w = w + 1;
|
|
199
|
+
|
|
200
|
+ // calling
|
|
201
|
+ while (runningScore < highestScore){
|
|
202
|
+ w += 1;
|
|
203
|
+ runningScore += currentScore;
|
|
204
|
+ currentScore = gameNextScore();
|
161
|
205
|
// each time through the inner loop
|
162
|
|
-
|
|
206
|
+ }
|
|
207
|
+
|
163
|
208
|
return w; // >= 3;
|
164
|
209
|
}
|
165
|
210
|
|
|
@@ -173,9 +218,14 @@ public class WriteLoops {
|
173
|
218
|
|
174
|
219
|
// do your while loop here
|
175
|
220
|
|
176
|
|
- // calling
|
|
221
|
+ // calling
|
|
222
|
+ do{
|
177
|
223
|
w = w + 1;
|
178
|
|
- // each time through the inner loop
|
|
224
|
+ runningScore += currentScore;
|
|
225
|
+ currentScore = gameNextScore();
|
|
226
|
+ }
|
|
227
|
+ while (runningScore < highestScore);
|
|
228
|
+ // each time through the inner loop
|
179
|
229
|
|
180
|
230
|
return w >= 3;
|
181
|
231
|
}
|
|
@@ -187,12 +237,19 @@ public class WriteLoops {
|
187
|
237
|
public int checkServerStatus() {
|
188
|
238
|
int w = 0;
|
189
|
239
|
String adminPhoneNumber = "+1 202 456 1111";
|
190
|
|
-
|
191
|
240
|
|
192
|
241
|
// calling
|
193
|
|
- w = w + 1;
|
|
242
|
+ //w = w + 1;
|
194
|
243
|
// each time through the inner loop
|
195
|
|
-
|
|
244
|
+ while (serverIsRunning()) {
|
|
245
|
+ waitFor(5);
|
|
246
|
+ w +=1;
|
|
247
|
+ }
|
|
248
|
+ if (!serverIsRunning()){
|
|
249
|
+ sendEmergencyText("Help!", adminPhoneNumber);
|
|
250
|
+ //tryServerRestart();
|
|
251
|
+ }
|
|
252
|
+
|
196
|
253
|
return w;
|
197
|
254
|
}
|
198
|
255
|
|
|
@@ -201,12 +258,16 @@ public class WriteLoops {
|
201
|
258
|
// and if it is, add 7 to “i”
|
202
|
259
|
public int loop50by7() {
|
203
|
260
|
int w = 0;
|
|
261
|
+ int i = 7;
|
204
|
262
|
|
|
263
|
+ // calling
|
|
264
|
+ //w = w + 1;
|
|
265
|
+ // each time through the inner loop
|
|
266
|
+ while (i < 50){
|
|
267
|
+ i +=7;
|
|
268
|
+ w +=1;
|
|
269
|
+ }
|
205
|
270
|
|
206
|
|
- // calling
|
207
|
|
- w = w + 1;
|
208
|
|
- // each time through the inner loop
|
209
|
|
-
|
210
|
271
|
return w;
|
211
|
272
|
}
|
212
|
273
|
|
|
@@ -238,12 +299,17 @@ public class WriteLoops {
|
238
|
299
|
public int rewriteFooAsFor() {
|
239
|
300
|
int w = 0;
|
240
|
301
|
int sumOfThrees = 0;
|
|
302
|
+ int i = 0;
|
|
303
|
+
|
|
304
|
+ // calling
|
|
305
|
+ w = w + 1;
|
|
306
|
+ // each time through the inner loop
|
|
307
|
+ while (i < threes_array.length){
|
|
308
|
+ sumOfThrees = threes_array[i];
|
|
309
|
+ i++;
|
|
310
|
+ w +=1;
|
|
311
|
+ }
|
241
|
312
|
|
242
|
|
-
|
243
|
|
- // calling
|
244
|
|
- w = w + 1;
|
245
|
|
- // each time through the inner loop
|
246
|
|
-
|
247
|
313
|
System.out.print("The Sum is ");
|
248
|
314
|
System.out.println(sumOfThrees);
|
249
|
315
|
|
|
@@ -256,11 +322,10 @@ public class WriteLoops {
|
256
|
322
|
int w = 0;
|
257
|
323
|
int sumOfThrees = 0;
|
258
|
324
|
|
259
|
|
-
|
260
|
|
- // calling
|
261
|
|
- w = w + 1;
|
262
|
|
- // each time through the inner loop
|
263
|
|
-
|
|
325
|
+ // calling
|
|
326
|
+ w = w + 1;
|
|
327
|
+ // each time through the inner loop
|
|
328
|
+
|
264
|
329
|
System.out.print("The Sum is ");
|
265
|
330
|
System.out.println(sumOfThrees);
|
266
|
331
|
|
|
@@ -279,11 +344,11 @@ public class WriteLoops {
|
279
|
344
|
boolean onTime = true;
|
280
|
345
|
|
281
|
346
|
// ADD YOUR CODE here.
|
282
|
|
-
|
283
|
|
- // be sure to call
|
284
|
|
- w = w + 1;
|
285
|
|
- // each time inside the loop
|
286
|
|
-
|
|
347
|
+
|
|
348
|
+ // be sure to call
|
|
349
|
+ w = w + 1;
|
|
350
|
+ // each time inside the loop
|
|
351
|
+
|
287
|
352
|
return w;
|
288
|
353
|
}
|
289
|
354
|
|
|
@@ -296,11 +361,10 @@ public class WriteLoops {
|
296
|
361
|
int w = 0;
|
297
|
362
|
int numberOfVotes = voteTallies.length;
|
298
|
363
|
|
299
|
|
-
|
300
|
|
- // calling
|
301
|
|
- w = w + 1;
|
302
|
|
- // each time through the inner loop
|
303
|
|
-
|
|
364
|
+ // calling
|
|
365
|
+ w = w + 1;
|
|
366
|
+ // each time through the inner loop
|
|
367
|
+
|
304
|
368
|
return w;
|
305
|
369
|
}
|
306
|
370
|
|
|
@@ -311,11 +375,10 @@ public class WriteLoops {
|
311
|
375
|
int w = 0;
|
312
|
376
|
int numberOfVotes = voteTallies.length;
|
313
|
377
|
|
|
378
|
+ // calling
|
|
379
|
+ w = w + 1;
|
|
380
|
+ // each time through the inner loop
|
314
|
381
|
|
315
|
|
- // calling
|
316
|
|
- w = w + 1;
|
317
|
|
- // each time through the inner loop
|
318
|
|
-
|
319
|
382
|
return w;
|
320
|
383
|
}
|
321
|
384
|
|
|
@@ -378,14 +441,15 @@ public class WriteLoops {
|
378
|
441
|
// return (i >= 3);
|
379
|
442
|
// };
|
380
|
443
|
// };
|
381
|
|
- private int summer = 0;
|
382
|
|
- private boolean isSummer() {
|
383
|
|
- if (summer == 3) {
|
384
|
|
- return true;
|
385
|
|
- }
|
386
|
|
- summer++;
|
387
|
|
- return false;
|
|
444
|
+ private int summer = 0;
|
|
445
|
+ private boolean isSummer() {
|
|
446
|
+ if (summer == 3) {
|
|
447
|
+ return true;
|
388
|
448
|
}
|
|
449
|
+ summer++;
|
|
450
|
+ return false;
|
|
451
|
+ }
|
|
452
|
+
|
389
|
453
|
private void sendEmergencyText(String mesg, String phone) {
|
390
|
454
|
}
|
391
|
455
|
|