|
@@ -17,94 +17,109 @@ public class WriteLoops {
|
17
|
17
|
|
18
|
18
|
public int oneToFive() {
|
19
|
19
|
int w = 0;
|
|
20
|
+ for(int i= 1; i<6; i++){
|
20
|
21
|
|
21
|
|
- // Write a FOR loop that counts from 1 to 10.
|
22
|
|
- // calling
|
23
|
22
|
w = w + 1;
|
24
|
|
- // each time through the loop
|
|
23
|
+ }
|
|
24
|
+ // Write a FOR loop that counts from 1 to 10.
|
|
25
|
+ // calling
|
|
26
|
+
|
|
27
|
+ // each time through the loop
|
25
|
28
|
|
26
|
29
|
// this will tell the test how many times the loop executed.
|
|
30
|
+
|
27
|
31
|
return w;
|
28
|
32
|
}
|
29
|
33
|
|
30
|
34
|
public int oneToTen() {
|
31
|
35
|
int w = 0;
|
32
|
|
-
|
33
|
|
- // Write a FOR loop that counts from 1 to 10.
|
34
|
|
- // calling
|
35
|
|
- w = w + 1;
|
36
|
|
- // each time through the loop
|
37
|
|
-
|
|
36
|
+ for ( int i = 0; i<10; i++){
|
|
37
|
+ // Write a FOR loop that counts from 1 to 10.
|
|
38
|
+ // calling
|
|
39
|
+ w = w + 1;
|
|
40
|
+ // each time through the loop
|
|
41
|
+ }
|
38
|
42
|
return w;
|
39
|
43
|
}
|
40
|
44
|
|
41
|
45
|
public int startAtTwentyOne() {
|
42
|
46
|
int w = 0;
|
43
|
|
-
|
44
|
|
- // Write a FOR loop that makes 10 iterations, start at 21.
|
45
|
|
- // calling
|
46
|
|
- w = w + 1;
|
47
|
|
- // each time through the loop
|
48
|
|
-
|
49
|
|
- return w;
|
|
47
|
+ for(int i = 21; i<32; i++){
|
|
48
|
+ // Write a FOR loop that makes 10 iterations, start at 21.
|
|
49
|
+ // calling
|
|
50
|
+ w = w + 1;
|
|
51
|
+ // each time through the loop
|
|
52
|
+ }
|
|
53
|
+ return w; // this should actually be "i<31" instead of "i<32";
|
50
|
54
|
}
|
51
|
55
|
|
52
|
56
|
public int countDown() {
|
53
|
57
|
int w = 0;
|
54
|
|
-
|
55
|
|
- // Write a FOR loop that counts down from 100 to 0.
|
56
|
|
- // calling
|
57
|
|
- w = w + 1;
|
58
|
|
- // each time through the loop
|
59
|
|
-
|
|
58
|
+ for(int i = 100; i>0; i--){
|
|
59
|
+ // Write a FOR loop that counts down from 100 to 0.
|
|
60
|
+ // calling
|
|
61
|
+ w = w + 1;
|
|
62
|
+ // each time through the loop
|
|
63
|
+ }
|
60
|
64
|
return w;
|
61
|
65
|
}
|
62
|
66
|
|
63
|
67
|
public int byTwoTo32() {
|
64
|
68
|
int w = 0;
|
|
69
|
+ for( int i =0; i<32; i+=2){
|
|
70
|
+ // Write a FOR loop from 0 to 32 by 2s.
|
|
71
|
+ // calling
|
65
|
72
|
|
66
|
|
- // Write a FOR loop from 0 to 32 by 2s.
|
67
|
|
- // calling
|
68
|
|
- w = w + 1;
|
69
|
|
- // each time through the loop
|
|
73
|
+ w = w + 1;
|
|
74
|
+ // each time through the loop
|
|
75
|
+ }
|
70
|
76
|
return w;
|
71
|
77
|
}
|
72
|
78
|
|
73
|
79
|
public int countDownFrom5000() {
|
74
|
80
|
int w = 0;
|
75
|
|
-
|
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
|
+ for(int i =1; i<5001; i+=11){
|
|
82
|
+ // Write a FOR loop from 1 to less than 5001 by 11s.
|
|
83
|
+ // calling
|
|
84
|
+ w = w + 1;
|
|
85
|
+ // each time through the loop
|
|
86
|
+ }
|
81
|
87
|
return w;
|
82
|
88
|
}
|
83
|
89
|
|
84
|
90
|
public int nestedFors() {
|
85
|
91
|
int w = 0;
|
86
|
|
-
|
87
|
|
- // Write a nested FOR loop(s), where one counts from
|
88
|
|
- // 0 to less than 20 and the inner one counts from 0 to 4
|
89
|
|
- // calling
|
|
92
|
+ for(int i=0; i<20; i++){
|
|
93
|
+ for(int j=0; j<5; j++){
|
90
|
94
|
w = w + 1;
|
91
|
|
- // each time through the inner loop
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ // Write a nested FOR loop(s), where one counts from
|
|
98
|
+ // 0 to less than 20 and the inner one counts from 0 to 4
|
|
99
|
+ // calling
|
92
|
100
|
|
|
101
|
+ // each time through the inner loop
|
|
102
|
+ }
|
93
|
103
|
return w;
|
|
104
|
+
|
94
|
105
|
}
|
95
|
106
|
|
96
|
107
|
public int helloZipCode() {
|
97
|
108
|
int w = 0;
|
98
|
|
-
|
99
|
|
- // Write a FOR loop that counts from 5 to 105. Put an IF
|
100
|
|
- // statement inside the loop that checks the
|
101
|
|
- // loop index counter and if it’s greater than 51,
|
102
|
|
- // prints “Hello Zipcode” instead of the statement w = w + 1;
|
|
109
|
+ for(int i=5; i<105; i++){
|
|
110
|
+ if( i > 51){
|
|
111
|
+ System.out.println("Hello Zipcode");
|
|
112
|
+ } else{
|
|
113
|
+ // Write a FOR loop that counts from 5 to 105. Put an IF
|
|
114
|
+ // statement inside the loop that checks the
|
|
115
|
+ // loop index counter and if it’s greater than 51,
|
|
116
|
+ // prints “Hello Zipcode” instead of the statement w = w + 1;
|
103
|
117
|
|
104
|
118
|
// calling
|
105
|
119
|
w = w + 1;
|
106
|
|
- // each time through the inner loop
|
107
|
|
-
|
|
120
|
+ // each time through the inner loop
|
|
121
|
+ }
|
|
122
|
+ }
|
108
|
123
|
return w;
|
109
|
124
|
}
|
110
|
125
|
|
|
@@ -131,17 +146,20 @@ public class WriteLoops {
|
131
|
146
|
// After the loop is done, print “Honey, I’m Home!”
|
132
|
147
|
public int driveHome() {
|
133
|
148
|
int w = 0;
|
134
|
|
-
|
135
|
|
- // you need to use a .equals for two Strings.
|
136
|
|
-
|
137
|
|
- // calling
|
|
149
|
+ while(!gpsCurrentLocation().equals("Home")){
|
|
150
|
+ driveSomeMore();
|
138
|
151
|
w = w + 1;
|
139
|
|
- // each time through the inner loop
|
140
|
|
-
|
|
152
|
+ }
|
|
153
|
+ System.out.println("Honey, I'm home!");
|
141
|
154
|
|
142
|
|
- return w;
|
|
155
|
+ return w;
|
143
|
156
|
}
|
144
|
157
|
|
|
158
|
+ // you need to use a .equals for two Strings.
|
|
159
|
+ // calling
|
|
160
|
+ // each time through the inner loop
|
|
161
|
+
|
|
162
|
+
|
145
|
163
|
// Getting harder...
|
146
|
164
|
// First declare and set “highestScore” to 236. Then set “currentScore” to
|
147
|
165
|
// “gameNextScore()”. Then write a WHILE loop that checks "runningScore"
|
|
@@ -153,13 +171,19 @@ public class WriteLoops {
|
153
|
171
|
int highestScore = 236;
|
154
|
172
|
int currentScore = gameNextScore();
|
155
|
173
|
int runningScore = 0;
|
156
|
|
-
|
157
|
174
|
// do your while loop here
|
158
|
|
-
|
159
|
|
- // calling
|
160
|
|
- w = w + 1;
|
161
|
|
- // each time through the inner loop
|
162
|
|
-
|
|
175
|
+ while(runningScore < highestScore){
|
|
176
|
+ if(runningScore < highestScore){
|
|
177
|
+ runningScore += currentScore;
|
|
178
|
+
|
|
179
|
+ w = w + 1;
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ }
|
|
183
|
+ // calling
|
|
184
|
+ currentScore = gameNextScore();
|
|
185
|
+ // each time through the inner loop
|
|
186
|
+
|
163
|
187
|
return w; // >= 3;
|
164
|
188
|
}
|
165
|
189
|
|
|
@@ -172,10 +196,14 @@ public class WriteLoops {
|
172
|
196
|
int runningScore = 0;
|
173
|
197
|
|
174
|
198
|
// do your while loop here
|
|
199
|
+ do{
|
|
200
|
+ if(runningScore < highestScore){
|
|
201
|
+ runningScore += currentScore;
|
|
202
|
+ }
|
|
203
|
+ w = w + 1;
|
175
|
204
|
|
176
|
|
- // calling
|
177
|
|
- w = w + 1;
|
178
|
|
- // each time through the inner loop
|
|
205
|
+ }
|
|
206
|
+ while(runningScore < highestScore);
|
179
|
207
|
|
180
|
208
|
return w >= 3;
|
181
|
209
|
}
|
|
@@ -187,26 +215,37 @@ public class WriteLoops {
|
187
|
215
|
public int checkServerStatus() {
|
188
|
216
|
int w = 0;
|
189
|
217
|
String adminPhoneNumber = "+1 202 456 1111";
|
190
|
|
-
|
|
218
|
+ while(serverIsRunning() == true){
|
|
219
|
+ if(serverIsRunning()==true){
|
|
220
|
+ waitFor(5);
|
|
221
|
+
|
|
222
|
+ }
|
|
223
|
+ w = w + 1;
|
|
224
|
+ }
|
|
225
|
+
|
|
226
|
+ if(serverIsRunning() == false){
|
|
227
|
+ sendEmergencyText("Help!", adminPhoneNumber);
|
|
228
|
+ tryServerRestart("Help!", adminPhoneNumber);
|
191
|
229
|
|
|
230
|
+ }
|
192
|
231
|
// calling
|
193
|
|
- w = w + 1;
|
|
232
|
+
|
194
|
233
|
// each time through the inner loop
|
195
|
|
-
|
196
|
234
|
return w;
|
|
235
|
+
|
197
|
236
|
}
|
198
|
237
|
|
|
238
|
+
|
199
|
239
|
// Declare an “int” i. Set i to 7.
|
200
|
240
|
// Write a WHILE loop that checks “i” is less than 50,
|
201
|
241
|
// and if it is, add 7 to “i”
|
202
|
242
|
public int loop50by7() {
|
203
|
243
|
int w = 0;
|
204
|
244
|
|
|
245
|
+ // calling
|
|
246
|
+ w = w + 1;
|
|
247
|
+ // each time through the inner loop
|
205
|
248
|
|
206
|
|
- // calling
|
207
|
|
- w = w + 1;
|
208
|
|
- // each time through the inner loop
|
209
|
|
-
|
210
|
249
|
return w;
|
211
|
250
|
}
|
212
|
251
|
|
|
@@ -239,11 +278,10 @@ public class WriteLoops {
|
239
|
278
|
int w = 0;
|
240
|
279
|
int sumOfThrees = 0;
|
241
|
280
|
|
242
|
|
-
|
243
|
|
- // calling
|
244
|
|
- w = w + 1;
|
245
|
|
- // each time through the inner loop
|
246
|
|
-
|
|
281
|
+ // calling
|
|
282
|
+ w = w + 1;
|
|
283
|
+ // each time through the inner loop
|
|
284
|
+
|
247
|
285
|
System.out.print("The Sum is ");
|
248
|
286
|
System.out.println(sumOfThrees);
|
249
|
287
|
|
|
@@ -256,11 +294,10 @@ public class WriteLoops {
|
256
|
294
|
int w = 0;
|
257
|
295
|
int sumOfThrees = 0;
|
258
|
296
|
|
259
|
|
-
|
260
|
|
- // calling
|
261
|
|
- w = w + 1;
|
262
|
|
- // each time through the inner loop
|
263
|
|
-
|
|
297
|
+ // calling
|
|
298
|
+ w = w + 1;
|
|
299
|
+ // each time through the inner loop
|
|
300
|
+
|
264
|
301
|
System.out.print("The Sum is ");
|
265
|
302
|
System.out.println(sumOfThrees);
|
266
|
303
|
|
|
@@ -279,11 +316,11 @@ public class WriteLoops {
|
279
|
316
|
boolean onTime = true;
|
280
|
317
|
|
281
|
318
|
// ADD YOUR CODE here.
|
282
|
|
-
|
283
|
|
- // be sure to call
|
284
|
|
- w = w + 1;
|
285
|
|
- // each time inside the loop
|
286
|
|
-
|
|
319
|
+
|
|
320
|
+ // be sure to call
|
|
321
|
+ w = w + 1;
|
|
322
|
+ // each time inside the loop
|
|
323
|
+
|
287
|
324
|
return w;
|
288
|
325
|
}
|
289
|
326
|
|
|
@@ -296,11 +333,10 @@ public class WriteLoops {
|
296
|
333
|
int w = 0;
|
297
|
334
|
int numberOfVotes = voteTallies.length;
|
298
|
335
|
|
299
|
|
-
|
300
|
|
- // calling
|
301
|
|
- w = w + 1;
|
302
|
|
- // each time through the inner loop
|
303
|
|
-
|
|
336
|
+ // calling
|
|
337
|
+ w = w + 1;
|
|
338
|
+ // each time through the inner loop
|
|
339
|
+
|
304
|
340
|
return w;
|
305
|
341
|
}
|
306
|
342
|
|
|
@@ -311,11 +347,10 @@ public class WriteLoops {
|
311
|
347
|
int w = 0;
|
312
|
348
|
int numberOfVotes = voteTallies.length;
|
313
|
349
|
|
|
350
|
+ // calling
|
|
351
|
+ w = w + 1;
|
|
352
|
+ // each time through the inner loop
|
314
|
353
|
|
315
|
|
- // calling
|
316
|
|
- w = w + 1;
|
317
|
|
- // each time through the inner loop
|
318
|
|
-
|
319
|
354
|
return w;
|
320
|
355
|
}
|
321
|
356
|
|
|
@@ -378,14 +413,15 @@ public class WriteLoops {
|
378
|
413
|
// return (i >= 3);
|
379
|
414
|
// };
|
380
|
415
|
// };
|
381
|
|
- private int summer = 0;
|
382
|
|
- private boolean isSummer() {
|
383
|
|
- if (summer == 3) {
|
384
|
|
- return true;
|
385
|
|
- }
|
386
|
|
- summer++;
|
387
|
|
- return false;
|
|
416
|
+ private int summer = 0;
|
|
417
|
+ private boolean isSummer() {
|
|
418
|
+ if (summer == 3) {
|
|
419
|
+ return true;
|
388
|
420
|
}
|
|
421
|
+ summer++;
|
|
422
|
+ return false;
|
|
423
|
+ }
|
|
424
|
+
|
389
|
425
|
private void sendEmergencyText(String mesg, String phone) {
|
390
|
426
|
}
|
391
|
427
|
|