|
@@ -97,9 +97,9 @@ public class WriteLoops {
|
97
|
97
|
// Write a nested FOR loop(s), where one counts from
|
98
|
98
|
// 0 to less than 20 and the inner one counts from 0 to 4
|
99
|
99
|
// calling
|
100
|
|
- for(int i=0; i>20; ++i) {
|
101
|
|
- for(int j=0; j>=4; ++j) {
|
102
|
|
- w += 1;
|
|
100
|
+ for(int i=0; i<20; ++i) {
|
|
101
|
+ for(int j=0; j<=4; ++j) {
|
|
102
|
+ w = w + 1;
|
103
|
103
|
}
|
104
|
104
|
}
|
105
|
105
|
|
|
@@ -116,14 +116,14 @@ public class WriteLoops {
|
116
|
116
|
// loop index counter and if it’s greater than 51,
|
117
|
117
|
// prints “Hello Zipcode” instead of the statement w = w + 1;
|
118
|
118
|
for(int i=5; i<=105; i++) {
|
119
|
|
- if(i <= 51){
|
120
|
|
- w += 1;
|
|
119
|
+ if(i <= 51){
|
|
120
|
+ w += 1;
|
121
|
121
|
} else {
|
122
|
122
|
System.out.println("Hello Zipcode");
|
123
|
123
|
}
|
124
|
124
|
}
|
125
|
125
|
// calling
|
126
|
|
-
|
|
126
|
+
|
127
|
127
|
// each time through the inner loop
|
128
|
128
|
|
129
|
129
|
return w;
|
|
@@ -156,16 +156,16 @@ public class WriteLoops {
|
156
|
156
|
// you need to use a .equals for two Strings.
|
157
|
157
|
while(gpsCurrentLocation().equals("Home") == false){
|
158
|
158
|
if(w<6){
|
159
|
|
- driveSomeMore();
|
160
|
|
- w++;
|
|
159
|
+ driveSomeMore();
|
|
160
|
+ w++;
|
161
|
161
|
} else {
|
162
|
|
- gpsCurrentLocation().equals("Home");
|
|
162
|
+ gpsCurrentLocation().equals("Home");
|
163
|
163
|
}
|
164
|
164
|
}
|
165
|
|
-
|
|
165
|
+
|
166
|
166
|
System.out.println("Honey, I’m Home!");
|
167
|
167
|
// calling
|
168
|
|
-
|
|
168
|
+
|
169
|
169
|
// each time through the inner loop
|
170
|
170
|
|
171
|
171
|
return w;
|
|
@@ -182,18 +182,15 @@ public class WriteLoops {
|
182
|
182
|
int highestScore = 236;
|
183
|
183
|
int currentScore = gameNextScore();
|
184
|
184
|
int runningScore = 0;
|
185
|
|
-
|
186
|
|
- while(runningScore < currentScore){
|
187
|
|
- currentScore += runningScore;
|
188
|
|
- currentScore += gameNextScore();
|
189
|
|
- w = w + 1;
|
|
185
|
+
|
|
186
|
+ while(runningScore < highestScore){
|
|
187
|
+ runningScore += currentScore;
|
|
188
|
+ currentScore = gameNextScore();
|
|
189
|
+ w = w + 1;
|
190
|
190
|
}
|
191
|
191
|
|
192
|
|
-
|
193
|
192
|
// calling
|
194
|
|
-
|
195
|
193
|
// each time through the inner loop
|
196
|
|
-
|
197
|
194
|
return w; //>= 3;
|
198
|
195
|
}
|
199
|
196
|
|
|
@@ -207,12 +204,13 @@ public class WriteLoops {
|
207
|
204
|
|
208
|
205
|
// do your while loop here
|
209
|
206
|
do {
|
210
|
|
- currentScore += runningScore;
|
211
|
|
- currentScore += gameNextScore();
|
|
207
|
+ runningScore += currentScore;
|
|
208
|
+ currentScore = gameNextScore();
|
212
|
209
|
w = w + 1;
|
213
|
210
|
} while(runningScore < highestScore);
|
214
|
211
|
// calling
|
215
|
212
|
|
|
213
|
+
|
216
|
214
|
// each time through the inner loop
|
217
|
215
|
|
218
|
216
|
return w >= 3;
|
|
@@ -226,8 +224,17 @@ public class WriteLoops {
|
226
|
224
|
int w = 0;
|
227
|
225
|
String adminPhoneNumber = "+1 202 456 1111";
|
228
|
226
|
|
|
227
|
+ while (serverIsRunning() == true) {
|
|
228
|
+ waitFor(5);
|
|
229
|
+ w = w + 1;
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ if(serverIsRunning() == false) {
|
|
233
|
+ sendEmergencyText("Help!", adminPhoneNumber);
|
|
234
|
+
|
|
235
|
+ }
|
229
|
236
|
// calling
|
230
|
|
- w = w + 1;
|
|
237
|
+
|
231
|
238
|
// each time through the inner loop
|
232
|
239
|
|
233
|
240
|
return w;
|
|
@@ -241,10 +248,10 @@ public class WriteLoops {
|
241
|
248
|
int i = 0;
|
242
|
249
|
// calling
|
243
|
250
|
while(i<50) {
|
244
|
|
- i+=7;
|
245
|
|
- w = w + 1;
|
|
251
|
+ i+=7;
|
|
252
|
+ w = w + 1;
|
246
|
253
|
}
|
247
|
|
-
|
|
254
|
+
|
248
|
255
|
// each time through the inner loop
|
249
|
256
|
|
250
|
257
|
return w;
|
|
@@ -278,9 +285,13 @@ public class WriteLoops {
|
278
|
285
|
public int rewriteFooAsFor() {
|
279
|
286
|
int w = 0;
|
280
|
287
|
int sumOfThrees = 0;
|
281
|
|
-
|
|
288
|
+
|
|
289
|
+ for(int i = 0; i < threes_array.length; i++){
|
|
290
|
+ sumOfThrees += threes_array[i];
|
|
291
|
+ w = w + 1;
|
|
292
|
+ }
|
282
|
293
|
// calling
|
283
|
|
- w = w + 1;
|
|
294
|
+
|
284
|
295
|
// each time through the inner loop
|
285
|
296
|
|
286
|
297
|
System.out.print("The Sum is ");
|
|
@@ -294,9 +305,15 @@ public class WriteLoops {
|
294
|
305
|
public int rewriteFooAsWhile() {
|
295
|
306
|
int w = 0;
|
296
|
307
|
int sumOfThrees = 0;
|
297
|
|
-
|
|
308
|
+ int idx = 0;
|
|
309
|
+
|
|
310
|
+ while(idx<threes_array.length) {
|
|
311
|
+ sumOfThrees += threes_array[idx];
|
|
312
|
+ idx++;
|
|
313
|
+ w = w + 1;
|
|
314
|
+ }
|
298
|
315
|
// calling
|
299
|
|
- w = w + 1;
|
|
316
|
+
|
300
|
317
|
// each time through the inner loop
|
301
|
318
|
|
302
|
319
|
System.out.print("The Sum is ");
|
|
@@ -315,11 +332,18 @@ public class WriteLoops {
|
315
|
332
|
public int manageYardAndJunior() {
|
316
|
333
|
int w = 0;
|
317
|
334
|
boolean onTime = true;
|
|
335
|
+ boolean yardNeedsMowed = true;
|
318
|
336
|
|
319
|
337
|
// ADD YOUR CODE here.
|
|
338
|
+ while(isSummer()) {
|
|
339
|
+ if(yardNeedsMowed) {
|
|
340
|
+ yellAtJuniorToMowLawn();
|
|
341
|
+ w = w + 1;
|
|
342
|
+ }
|
320
|
343
|
|
|
344
|
+ }
|
321
|
345
|
// be sure to call
|
322
|
|
- w = w + 1;
|
|
346
|
+ sendJuniorBackToSchool("First day of school");
|
323
|
347
|
// each time inside the loop
|
324
|
348
|
|
325
|
349
|
return w;
|
|
@@ -334,8 +358,11 @@ public class WriteLoops {
|
334
|
358
|
int w = 0;
|
335
|
359
|
int numberOfVotes = voteTallies.length;
|
336
|
360
|
|
337
|
|
- // calling
|
338
|
|
- w = w + 1;
|
|
361
|
+ for(int i = 0; i < numberOfVotes; i++) {
|
|
362
|
+ System.out.println(voteTallies[i]);
|
|
363
|
+ w = w + 1;
|
|
364
|
+ }// calling
|
|
365
|
+
|
339
|
366
|
// each time through the inner loop
|
340
|
367
|
|
341
|
368
|
return w;
|
|
@@ -346,10 +373,16 @@ public class WriteLoops {
|
346
|
373
|
// where you are.
|
347
|
374
|
public int tallyVote2() {
|
348
|
375
|
int w = 0;
|
|
376
|
+ int idx = 0;
|
349
|
377
|
int numberOfVotes = voteTallies.length;
|
350
|
378
|
|
|
379
|
+ while(idx < numberOfVotes) {
|
|
380
|
+ System.out.println(voteTallies[idx]);
|
|
381
|
+ idx++;
|
|
382
|
+ w = w + 1;
|
|
383
|
+ }
|
351
|
384
|
// calling
|
352
|
|
- w = w + 1;
|
|
385
|
+
|
353
|
386
|
// each time through the inner loop
|
354
|
387
|
|
355
|
388
|
return w;
|