|
@@ -1,3 +1,6 @@
|
|
1
|
+
|
|
2
|
+package FirstSaturday;
|
|
3
|
+
|
1
|
4
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
2
|
5
|
|
3
|
6
|
import java.awt.SystemTray;
|
|
@@ -18,54 +21,59 @@ public class WriteLoops {
|
18
|
21
|
public int oneToFive() {
|
19
|
22
|
int w = 0;
|
20
|
23
|
|
21
|
|
- // Write a FOR loop that counts from 1 to 10.
|
|
24
|
+ // Write a FOR loop that counts from 1 to 5.
|
|
25
|
+ for (int i = 0; i < 5; i++){
|
22
|
26
|
// calling
|
23
|
27
|
w = w + 1;
|
24
|
28
|
// each time through the loop
|
25
|
|
-
|
|
29
|
+ }
|
26
|
30
|
// this will tell the test how many times the loop executed.
|
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
|
47
|
|
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
|
|
-
|
|
48
|
+ for (int i = 21; i <= 31; i++){
|
|
49
|
+ // Write a FOR loop that makes 10 iterations, start at 21.
|
|
50
|
+ // calling
|
|
51
|
+ w = w + 1;
|
|
52
|
+ // each time through the loop
|
|
53
|
+ }
|
49
|
54
|
return w;
|
50
|
55
|
}
|
51
|
56
|
|
52
|
57
|
public int countDown() {
|
53
|
58
|
int w = 0;
|
54
|
59
|
|
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
|
|
-
|
|
60
|
+ for (int i = 100; i > 0; i--){
|
|
61
|
+ // Write a FOR loop that counts down from 100 to 0.
|
|
62
|
+ // calling
|
|
63
|
+ w = w + 1;
|
|
64
|
+ // each time through the loop
|
|
65
|
+ }
|
60
|
66
|
return w;
|
61
|
67
|
}
|
62
|
68
|
|
63
|
69
|
public int byTwoTo32() {
|
64
|
70
|
int w = 0;
|
65
|
71
|
|
66
|
|
- // Write a FOR loop from 0 to 32 by 2s.
|
67
|
|
- // calling
|
68
|
|
- w = w + 1;
|
|
72
|
+ for (int i = 0; i <= 32; i = i + 2){
|
|
73
|
+ // Write a FOR loop from 0 to 32 by 2s.
|
|
74
|
+ // calling
|
|
75
|
+ w = w + 1;
|
|
76
|
+ }
|
69
|
77
|
// each time through the loop
|
70
|
78
|
return w;
|
71
|
79
|
}
|
|
@@ -73,38 +81,50 @@ public class WriteLoops {
|
73
|
81
|
public int countDownFrom5000() {
|
74
|
82
|
int w = 0;
|
75
|
83
|
|
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
|
|
-
|
|
84
|
+ for (int i = 1; i < 5001; i = i + 11){
|
|
85
|
+ // Write a FOR loop from 1 to less than 5001 by 11s.
|
|
86
|
+ // calling
|
|
87
|
+ w = w + 1;
|
|
88
|
+ // each time through the loop
|
|
89
|
+
|
|
90
|
+ }
|
81
|
91
|
return w;
|
82
|
92
|
}
|
83
|
93
|
|
84
|
94
|
public int nestedFors() {
|
85
|
95
|
int w = 0;
|
86
|
96
|
|
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
|
|
97
|
+ for (int i = 0; i < 20; i++){
|
|
98
|
+ // Write a nested FOR loop(s), where one counts from
|
|
99
|
+ // 0 to less than 20 and the inner one counts from 0 to 4
|
|
100
|
+ // calling
|
|
101
|
+ for (int j = 0; j < 5; j++){
|
90
|
102
|
w = w + 1;
|
91
|
|
- // each time through the inner loop
|
92
|
|
-
|
|
103
|
+ }
|
|
104
|
+ // each time through the inner loop
|
|
105
|
+ }
|
93
|
106
|
return w;
|
94
|
107
|
}
|
95
|
108
|
|
96
|
109
|
public int helloZipCode() {
|
97
|
110
|
int w = 0;
|
98
|
111
|
|
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;
|
|
112
|
+ for (int i = 5; i <= 105; i++){
|
|
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
|
|
- // calling
|
|
118
|
+ System.out.println(w);
|
|
119
|
+
|
|
120
|
+ // calling
|
|
121
|
+ if (i > 51){
|
|
122
|
+ System.out.println("Hello Zipcode");
|
|
123
|
+ } else {
|
105
|
124
|
w = w + 1;
|
|
125
|
+ }
|
106
|
126
|
// each time through the inner loop
|
107
|
|
-
|
|
127
|
+ }
|
108
|
128
|
return w;
|
109
|
129
|
}
|
110
|
130
|
|
|
@@ -132,14 +152,17 @@ public class WriteLoops {
|
132
|
152
|
public int driveHome() {
|
133
|
153
|
int w = 0;
|
134
|
154
|
|
|
155
|
+ gpsCurrentLocation();
|
135
|
156
|
// you need to use a .equals for two Strings.
|
136
|
157
|
|
|
158
|
+ while (gpsCurrentLocation().equals("Not Home")){
|
|
159
|
+ driveSomeMore();
|
|
160
|
+
|
137
|
161
|
// calling
|
138
|
162
|
w = w + 1;
|
139
|
163
|
// each time through the inner loop
|
140
|
|
-
|
141
|
|
-
|
142
|
|
- return w;
|
|
164
|
+ }
|
|
165
|
+ return w;
|
143
|
166
|
}
|
144
|
167
|
|
145
|
168
|
// Getting harder...
|
|
@@ -155,11 +178,15 @@ public class WriteLoops {
|
155
|
178
|
int runningScore = 0;
|
156
|
179
|
|
157
|
180
|
// do your while loop here
|
158
|
|
-
|
|
181
|
+ while (runningScore < highestScore) {
|
|
182
|
+ runningScore += currentScore;
|
159
|
183
|
// calling
|
160
|
|
- w = w + 1;
|
|
184
|
+
|
|
185
|
+ if (runningScore < highestScore){
|
|
186
|
+ w = w + 1;
|
|
187
|
+ }
|
161
|
188
|
// each time through the inner loop
|
162
|
|
-
|
|
189
|
+ }
|
163
|
190
|
return w; // >= 3;
|
164
|
191
|
}
|
165
|
192
|
|
|
@@ -172,10 +199,18 @@ public class WriteLoops {
|
172
|
199
|
int runningScore = 0;
|
173
|
200
|
|
174
|
201
|
// do your while loop here
|
175
|
|
-
|
176
|
|
- // calling
|
|
202
|
+ do {
|
|
203
|
+ runningScore += currentScore;
|
177
|
204
|
w = w + 1;
|
178
|
|
- // each time through the inner loop
|
|
205
|
+ if (runningScore < highestScore){
|
|
206
|
+
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ } while (runningScore < highestScore);
|
|
210
|
+
|
|
211
|
+ // calling
|
|
212
|
+
|
|
213
|
+ // each time through the inner loop
|
179
|
214
|
|
180
|
215
|
return w >= 3;
|
181
|
216
|
}
|
|
@@ -187,12 +222,17 @@ public class WriteLoops {
|
187
|
222
|
public int checkServerStatus() {
|
188
|
223
|
int w = 0;
|
189
|
224
|
String adminPhoneNumber = "+1 202 456 1111";
|
190
|
|
-
|
191
|
225
|
|
192
|
|
- // calling
|
193
|
|
- w = w + 1;
|
194
|
|
- // each time through the inner loop
|
195
|
|
-
|
|
226
|
+ while(serverIsRunning()){
|
|
227
|
+ waitFor(5);
|
|
228
|
+ // calling
|
|
229
|
+ if (serverIsRunning() == false){
|
|
230
|
+ sendEmergencyText("Help!", adminPhoneNumber);
|
|
231
|
+ tryServerRestart("Help!", adminPhoneNumber);
|
|
232
|
+ }
|
|
233
|
+ w = w + 1;
|
|
234
|
+ // each time through the inner loop
|
|
235
|
+ }
|
196
|
236
|
return w;
|
197
|
237
|
}
|
198
|
238
|
|
|
@@ -201,12 +241,15 @@ public class WriteLoops {
|
201
|
241
|
// and if it is, add 7 to “i”
|
202
|
242
|
public int loop50by7() {
|
203
|
243
|
int w = 0;
|
|
244
|
+ int i = 7;
|
204
|
245
|
|
205
|
|
-
|
206
|
|
- // calling
|
|
246
|
+ while (i < 50){
|
|
247
|
+ i += 7;
|
207
|
248
|
w = w + 1;
|
208
|
|
- // each time through the inner loop
|
209
|
|
-
|
|
249
|
+ }
|
|
250
|
+ // calling
|
|
251
|
+ // each time through the inner loop
|
|
252
|
+
|
210
|
253
|
return w;
|
211
|
254
|
}
|
212
|
255
|
|
|
@@ -239,11 +282,15 @@ public class WriteLoops {
|
239
|
282
|
int w = 0;
|
240
|
283
|
int sumOfThrees = 0;
|
241
|
284
|
|
242
|
|
-
|
|
285
|
+ for (int i = 0; i < threes_array.length; i++){
|
243
|
286
|
// calling
|
|
287
|
+ sumOfThrees = threes_array[i];
|
|
288
|
+
|
244
|
289
|
w = w + 1;
|
|
290
|
+
|
245
|
291
|
// each time through the inner loop
|
246
|
|
-
|
|
292
|
+ }
|
|
293
|
+
|
247
|
294
|
System.out.print("The Sum is ");
|
248
|
295
|
System.out.println(sumOfThrees);
|
249
|
296
|
|
|
@@ -255,12 +302,16 @@ public class WriteLoops {
|
255
|
302
|
public int rewriteFooAsWhile() {
|
256
|
303
|
int w = 0;
|
257
|
304
|
int sumOfThrees = 0;
|
|
305
|
+ int i = 0;
|
258
|
306
|
|
259
|
|
-
|
260
|
|
- // calling
|
|
307
|
+ while (i < threes_array.length){
|
|
308
|
+ // calling
|
|
309
|
+ sumOfThrees = threes_array[i];
|
|
310
|
+ i++;
|
261
|
311
|
w = w + 1;
|
262
|
|
- // each time through the inner loop
|
263
|
|
-
|
|
312
|
+ }
|
|
313
|
+ // each time through the inner loop
|
|
314
|
+
|
264
|
315
|
System.out.print("The Sum is ");
|
265
|
316
|
System.out.println(sumOfThrees);
|
266
|
317
|
|
|
@@ -277,13 +328,22 @@ public class WriteLoops {
|
277
|
328
|
public int manageYardAndJunior() {
|
278
|
329
|
int w = 0;
|
279
|
330
|
boolean onTime = true;
|
|
331
|
+ boolean yardNeedsMowed = true;
|
|
332
|
+
|
|
333
|
+ while (isSummer()){
|
|
334
|
+ w = w + 1;
|
|
335
|
+ if (yardNeedsMowed){
|
|
336
|
+ yellAtJuniorToMowLawn();
|
|
337
|
+
|
|
338
|
+ }
|
|
339
|
+ }
|
280
|
340
|
|
281
|
341
|
// ADD YOUR CODE here.
|
282
|
|
-
|
283
|
|
- // be sure to call
|
284
|
|
- w = w + 1;
|
285
|
|
- // each time inside the loop
|
|
342
|
+
|
|
343
|
+ // be sure to call
|
286
|
344
|
|
|
345
|
+ // each time inside the loop
|
|
346
|
+ sendJuniorBackToSchool("September 12");
|
287
|
347
|
return w;
|
288
|
348
|
}
|
289
|
349
|
|
|
@@ -296,11 +356,13 @@ public class WriteLoops {
|
296
|
356
|
int w = 0;
|
297
|
357
|
int numberOfVotes = voteTallies.length;
|
298
|
358
|
|
299
|
|
-
|
300
|
|
- // calling
|
301
|
|
- w = w + 1;
|
302
|
|
- // each time through the inner loop
|
303
|
|
-
|
|
359
|
+ for (int i = 0; i < numberOfVotes; i++){
|
|
360
|
+ // calling
|
|
361
|
+ System.out.println(voteTallies[i]);
|
|
362
|
+ w = w + 1;
|
|
363
|
+ // each time through the inner loop
|
|
364
|
+
|
|
365
|
+ }
|
304
|
366
|
return w;
|
305
|
367
|
}
|
306
|
368
|
|
|
@@ -310,12 +372,15 @@ public class WriteLoops {
|
310
|
372
|
public int tallyVote2() {
|
311
|
373
|
int w = 0;
|
312
|
374
|
int numberOfVotes = voteTallies.length;
|
|
375
|
+ int idx = 0;
|
313
|
376
|
|
314
|
|
-
|
315
|
|
- // calling
|
316
|
|
- w = w + 1;
|
317
|
|
- // each time through the inner loop
|
318
|
|
-
|
|
377
|
+ while(idx < voteTallies.length){
|
|
378
|
+ System.out.println(voteTallies[idx]);
|
|
379
|
+ idx++;
|
|
380
|
+ // calling
|
|
381
|
+ w = w + 1;
|
|
382
|
+ // each time through the inner loop
|
|
383
|
+ }
|
319
|
384
|
return w;
|
320
|
385
|
}
|
321
|
386
|
|
|
@@ -378,14 +443,15 @@ public class WriteLoops {
|
378
|
443
|
// return (i >= 3);
|
379
|
444
|
// };
|
380
|
445
|
// };
|
381
|
|
- private int summer = 0;
|
382
|
|
- private boolean isSummer() {
|
383
|
|
- if (summer == 3) {
|
384
|
|
- return true;
|
385
|
|
- }
|
386
|
|
- summer++;
|
387
|
|
- return false;
|
|
446
|
+ private int summer = 0;
|
|
447
|
+ private boolean isSummer() {
|
|
448
|
+ if (summer == 3) {
|
|
449
|
+ return true;
|
388
|
450
|
}
|
|
451
|
+ summer++;
|
|
452
|
+ return false;
|
|
453
|
+ }
|
|
454
|
+
|
389
|
455
|
private void sendEmergencyText(String mesg, String phone) {
|
390
|
456
|
}
|
391
|
457
|
|