|
@@ -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=22; i<33; 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 + 0;
|
|
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=5001; i>0; 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,11 @@ 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
|
90
|
|
- w = w + 1;
|
91
|
|
- // each time through the inner loop
|
|
101
|
+ // calling
|
|
102
|
+ for (int i=0; i<20; i++){
|
|
103
|
+ for (int b=0; b<=4; b++){
|
|
104
|
+ w = w + 1;}}
|
|
105
|
+ // each time through the inner loop
|
92
|
106
|
|
93
|
107
|
return w;
|
94
|
108
|
}
|
|
@@ -101,10 +115,14 @@ public class WriteLoops {
|
101
|
115
|
// loop index counter and if it’s greater than 51,
|
102
|
116
|
// prints “Hello Zipcode” instead of the statement w = w + 1;
|
103
|
117
|
|
104
|
|
- // calling
|
105
|
|
- w = w + 1;
|
106
|
|
- // each time through the inner loop
|
107
|
|
-
|
|
118
|
+ // calling
|
|
119
|
+ for (int i=0; i<150; i++){
|
|
120
|
+ if (i>46){System.out.println("Hello ZipCode");}
|
|
121
|
+ else{
|
|
122
|
+ w = w + 1;}
|
|
123
|
+ }
|
|
124
|
+ // each time through the inner loop
|
|
125
|
+
|
108
|
126
|
return w;
|
109
|
127
|
}
|
110
|
128
|
|
|
@@ -131,15 +149,15 @@ public class WriteLoops {
|
131
|
149
|
// After the loop is done, print “Honey, I’m Home!”
|
132
|
150
|
public int driveHome() {
|
133
|
151
|
int w = 0;
|
134
|
|
-
|
135
|
|
- // you need to use a .equals for two Strings.
|
136
|
|
-
|
|
152
|
+ while (!gpsCurrentLocation().equals("Home")) {
|
|
153
|
+ // you need to use a .equals for two Strings.
|
|
154
|
+ driveSomeMore();
|
137
|
155
|
// calling
|
138
|
156
|
w = w + 1;
|
139
|
157
|
// each time through the inner loop
|
140
|
|
-
|
141
|
|
-
|
142
|
|
- return w;
|
|
158
|
+ }
|
|
159
|
+ System.out.println("Honey, I'm Home!");
|
|
160
|
+ return w;
|
143
|
161
|
}
|
144
|
162
|
|
145
|
163
|
// Getting harder...
|
|
@@ -153,13 +171,13 @@ public class WriteLoops {
|
153
|
171
|
int highestScore = 236;
|
154
|
172
|
int currentScore = gameNextScore();
|
155
|
173
|
int runningScore = 0;
|
156
|
|
-
|
157
|
|
- // do your while loop here
|
158
|
|
-
|
|
174
|
+ while (runningScore<highestScore){
|
|
175
|
+ // do your while loop here
|
|
176
|
+ runningScore+= currentScore;
|
159
|
177
|
// calling
|
160
|
178
|
w = w + 1;
|
161
|
179
|
// each time through the inner loop
|
162
|
|
-
|
|
180
|
+ }
|
163
|
181
|
return w; // >= 3;
|
164
|
182
|
}
|
165
|
183
|
|
|
@@ -173,9 +191,9 @@ public class WriteLoops {
|
173
|
191
|
|
174
|
192
|
// do your while loop here
|
175
|
193
|
|
176
|
|
- // calling
|
177
|
|
- w = w + 1;
|
178
|
|
- // each time through the inner loop
|
|
194
|
+ // calling
|
|
195
|
+ w = w + 1;
|
|
196
|
+ // each time through the inner loop
|
179
|
197
|
|
180
|
198
|
return w >= 3;
|
181
|
199
|
}
|
|
@@ -187,12 +205,11 @@ public class WriteLoops {
|
187
|
205
|
public int checkServerStatus() {
|
188
|
206
|
int w = 0;
|
189
|
207
|
String adminPhoneNumber = "+1 202 456 1111";
|
190
|
|
-
|
191
|
208
|
|
192
|
209
|
// calling
|
193
|
210
|
w = w + 1;
|
194
|
211
|
// each time through the inner loop
|
195
|
|
-
|
|
212
|
+
|
196
|
213
|
return w;
|
197
|
214
|
}
|
198
|
215
|
|
|
@@ -202,11 +219,10 @@ public class WriteLoops {
|
202
|
219
|
public int loop50by7() {
|
203
|
220
|
int w = 0;
|
204
|
221
|
|
|
222
|
+ // calling
|
|
223
|
+ w = w + 1;
|
|
224
|
+ // each time through the inner loop
|
205
|
225
|
|
206
|
|
- // calling
|
207
|
|
- w = w + 1;
|
208
|
|
- // each time through the inner loop
|
209
|
|
-
|
210
|
226
|
return w;
|
211
|
227
|
}
|
212
|
228
|
|
|
@@ -239,11 +255,10 @@ public class WriteLoops {
|
239
|
255
|
int w = 0;
|
240
|
256
|
int sumOfThrees = 0;
|
241
|
257
|
|
242
|
|
-
|
243
|
|
- // calling
|
244
|
|
- w = w + 1;
|
245
|
|
- // each time through the inner loop
|
246
|
|
-
|
|
258
|
+ // calling
|
|
259
|
+ w = w + 1;
|
|
260
|
+ // each time through the inner loop
|
|
261
|
+
|
247
|
262
|
System.out.print("The Sum is ");
|
248
|
263
|
System.out.println(sumOfThrees);
|
249
|
264
|
|
|
@@ -256,11 +271,10 @@ public class WriteLoops {
|
256
|
271
|
int w = 0;
|
257
|
272
|
int sumOfThrees = 0;
|
258
|
273
|
|
259
|
|
-
|
260
|
|
- // calling
|
261
|
|
- w = w + 1;
|
262
|
|
- // each time through the inner loop
|
263
|
|
-
|
|
274
|
+ // calling
|
|
275
|
+ w = w + 1;
|
|
276
|
+ // each time through the inner loop
|
|
277
|
+
|
264
|
278
|
System.out.print("The Sum is ");
|
265
|
279
|
System.out.println(sumOfThrees);
|
266
|
280
|
|
|
@@ -279,15 +293,16 @@ public class WriteLoops {
|
279
|
293
|
boolean onTime = true;
|
280
|
294
|
|
281
|
295
|
// ADD YOUR CODE here.
|
282
|
|
-
|
283
|
|
- // be sure to call
|
284
|
|
- w = w + 1;
|
285
|
|
- // each time inside the loop
|
286
|
|
-
|
|
296
|
+
|
|
297
|
+ // be sure to call
|
|
298
|
+ w = w + 1;
|
|
299
|
+ // each time inside the loop
|
|
300
|
+
|
287
|
301
|
return w;
|
288
|
302
|
}
|
289
|
303
|
|
290
|
|
- String voteTallies[] = { "Lincoln", "Washington", "Adams", "Lincoln", "Washington", "Adams", "Lincoln",
|
|
304
|
+ String voteTallies[] = { "Lincoln", "Washington", "Adams", "Lincoln", "Washington",
|
|
305
|
+ "Adams", "Lincoln",
|
291
|
306
|
"Washington", "Adams", "Lincoln", "Washington", "Adams", "Roosevelt" };
|
292
|
307
|
|
293
|
308
|
// Given an array voteTallies[], write a FOR loop that prints out each value in
|
|
@@ -296,11 +311,10 @@ public class WriteLoops {
|
296
|
311
|
int w = 0;
|
297
|
312
|
int numberOfVotes = voteTallies.length;
|
298
|
313
|
|
299
|
|
-
|
300
|
|
- // calling
|
301
|
|
- w = w + 1;
|
302
|
|
- // each time through the inner loop
|
303
|
|
-
|
|
314
|
+ // calling
|
|
315
|
+ w = w + 1;
|
|
316
|
+ // each time through the inner loop
|
|
317
|
+
|
304
|
318
|
return w;
|
305
|
319
|
}
|
306
|
320
|
|
|
@@ -311,11 +325,10 @@ public class WriteLoops {
|
311
|
325
|
int w = 0;
|
312
|
326
|
int numberOfVotes = voteTallies.length;
|
313
|
327
|
|
|
328
|
+ // calling
|
|
329
|
+ w = w + 1;
|
|
330
|
+ // each time through the inner loop
|
314
|
331
|
|
315
|
|
- // calling
|
316
|
|
- w = w + 1;
|
317
|
|
- // each time through the inner loop
|
318
|
|
-
|
319
|
332
|
return w;
|
320
|
333
|
}
|
321
|
334
|
|
|
@@ -378,14 +391,15 @@ public class WriteLoops {
|
378
|
391
|
// return (i >= 3);
|
379
|
392
|
// };
|
380
|
393
|
// };
|
381
|
|
- private int summer = 0;
|
382
|
|
- private boolean isSummer() {
|
383
|
|
- if (summer == 3) {
|
384
|
|
- return true;
|
385
|
|
- }
|
386
|
|
- summer++;
|
387
|
|
- return false;
|
|
394
|
+ private int summer = 0;
|
|
395
|
+ private boolean isSummer() {
|
|
396
|
+ if (summer == 3) {
|
|
397
|
+ return true;
|
388
|
398
|
}
|
|
399
|
+ summer++;
|
|
400
|
+ return false;
|
|
401
|
+ }
|
|
402
|
+
|
389
|
403
|
private void sendEmergencyText(String mesg, String phone) {
|
390
|
404
|
}
|
391
|
405
|
|