|
@@ -1,3 +1,5 @@
|
|
1
|
+package FirstSaturday;
|
|
2
|
+
|
1
|
3
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
2
|
4
|
|
3
|
5
|
import java.awt.SystemTray;
|
|
@@ -17,94 +19,74 @@ public class WriteLoops {
|
17
|
19
|
|
18
|
20
|
public int oneToFive() {
|
19
|
21
|
int w = 0;
|
20
|
|
-
|
21
|
|
- // Write a FOR loop that counts from 1 to 10.
|
22
|
|
- // calling
|
|
22
|
+ for (int i = 1; i <= 5; i++){
|
23
|
23
|
w = w + 1;
|
24
|
|
- // each time through the loop
|
25
|
|
-
|
26
|
|
- // this will tell the test how many times the loop executed.
|
|
24
|
+ }
|
27
|
25
|
return w;
|
28
|
26
|
}
|
29
|
27
|
|
30
|
28
|
public int oneToTen() {
|
31
|
29
|
int w = 0;
|
|
30
|
+ for (int i = 1; i <= 10; i++){
|
|
31
|
+ w = w + 1;
|
|
32
|
+ }
|
32
|
33
|
|
33
|
|
- // Write a FOR loop that counts from 1 to 10.
|
34
|
|
- // calling
|
35
|
|
- w = w + 1;
|
36
|
|
- // each time through the loop
|
37
|
|
-
|
38
|
34
|
return w;
|
39
|
35
|
}
|
40
|
36
|
|
41
|
37
|
public int startAtTwentyOne() {
|
42
|
38
|
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
|
|
-
|
|
39
|
+ for (int i = 21; i <=31; i++){
|
|
40
|
+ w = w + 1;
|
|
41
|
+ }
|
49
|
42
|
return w;
|
50
|
43
|
}
|
51
|
44
|
|
52
|
45
|
public int countDown() {
|
53
|
46
|
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
|
|
-
|
|
47
|
+ for (int i = 100; i > 0; i--){
|
|
48
|
+ w = w + 1;
|
|
49
|
+ }
|
60
|
50
|
return w;
|
61
|
51
|
}
|
62
|
52
|
|
63
|
53
|
public int byTwoTo32() {
|
64
|
54
|
int w = 0;
|
65
|
|
-
|
66
|
|
- // Write a FOR loop from 0 to 32 by 2s.
|
67
|
|
- // calling
|
68
|
|
- w = w + 1;
|
69
|
|
- // each time through the loop
|
|
55
|
+ for (int i = 0; i < 32; i += 2){
|
|
56
|
+ w = w + 1;
|
|
57
|
+ }
|
70
|
58
|
return w;
|
71
|
59
|
}
|
72
|
60
|
|
73
|
61
|
public int countDownFrom5000() {
|
74
|
62
|
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
|
|
-
|
|
63
|
+ for (int i = 1; i <= 5000; i +=11){
|
|
64
|
+ w = w + 1;
|
|
65
|
+ }
|
81
|
66
|
return w;
|
82
|
67
|
}
|
83
|
68
|
|
84
|
69
|
public int nestedFors() {
|
85
|
70
|
int w = 0;
|
|
71
|
+ for (int i = 0; i < 20; i++){
|
86
|
72
|
|
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
|
|
73
|
+ for (int j = 0; j <= 4; j++){
|
90
|
74
|
w = w + 1;
|
91
|
|
- // each time through the inner loop
|
|
75
|
+ }
|
92
|
76
|
|
|
77
|
+ }
|
93
|
78
|
return w;
|
94
|
79
|
}
|
95
|
80
|
|
96
|
81
|
public int helloZipCode() {
|
97
|
82
|
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;
|
103
|
|
-
|
104
|
|
- // calling
|
|
83
|
+ for (int i = 5; i <= 105; i++){
|
|
84
|
+ if (i > 51){
|
|
85
|
+ System.out.print("Hello Zipcode");
|
|
86
|
+ }else{
|
105
|
87
|
w = w + 1;
|
106
|
|
- // each time through the inner loop
|
107
|
|
-
|
|
88
|
+ }
|
|
89
|
+ }
|
108
|
90
|
return w;
|
109
|
91
|
}
|
110
|
92
|
|
|
@@ -123,7 +105,9 @@ public class WriteLoops {
|
123
|
105
|
System.out.println("Eww.");
|
124
|
106
|
i = i - 1;
|
125
|
107
|
} while (i > 0);
|
126
|
|
- // what's the primary difference between them?!?
|
|
108
|
+ /** what's the primary difference between them?!?
|
|
109
|
+ * Unlike the while loop,
|
|
110
|
+ * the do while loop will run atleast once.*/
|
127
|
111
|
}
|
128
|
112
|
|
129
|
113
|
// Write a WHILE loop that checks “gpsCurrentLocation()”
|
|
@@ -131,15 +115,13 @@ public class WriteLoops {
|
131
|
115
|
// After the loop is done, print “Honey, I’m Home!”
|
132
|
116
|
public int driveHome() {
|
133
|
117
|
int w = 0;
|
134
|
|
-
|
135
|
|
- // you need to use a .equals for two Strings.
|
136
|
|
-
|
137
|
|
- // calling
|
|
118
|
+ while (!gpsCurrentLocation().equals("Home")){
|
|
119
|
+ driveSomeMore();
|
138
|
120
|
w = w + 1;
|
139
|
|
- // each time through the inner loop
|
140
|
|
-
|
141
|
121
|
|
142
|
|
- return w;
|
|
122
|
+ }
|
|
123
|
+ System.out.print("Honey, I'm Home!");
|
|
124
|
+ return w;
|
143
|
125
|
}
|
144
|
126
|
|
145
|
127
|
// Getting harder...
|
|
@@ -155,12 +137,12 @@ public class WriteLoops {
|
155
|
137
|
int runningScore = 0;
|
156
|
138
|
|
157
|
139
|
// do your while loop here
|
158
|
|
-
|
159
|
|
- // calling
|
|
140
|
+ while (runningScore < highestScore){
|
|
141
|
+ runningScore = currentScore + runningScore;
|
160
|
142
|
w = w + 1;
|
161
|
|
- // each time through the inner loop
|
162
|
|
-
|
163
|
|
- return w; // >= 3;
|
|
143
|
+ System.out.print(w);
|
|
144
|
+ }
|
|
145
|
+ return w;
|
164
|
146
|
}
|
165
|
147
|
|
166
|
148
|
// Rewrite the previous WHILE loop as a DO..WHILE loop.
|
|
@@ -172,11 +154,10 @@ public class WriteLoops {
|
172
|
154
|
int runningScore = 0;
|
173
|
155
|
|
174
|
156
|
// do your while loop here
|
175
|
|
-
|
176
|
|
- // calling
|
|
157
|
+ do {
|
|
158
|
+ runningScore = currentScore + runningScore;
|
177
|
159
|
w = w + 1;
|
178
|
|
- // each time through the inner loop
|
179
|
|
-
|
|
160
|
+ }while (runningScore < highestScore);
|
180
|
161
|
return w >= 3;
|
181
|
162
|
}
|
182
|
163
|
|
|
@@ -187,12 +168,15 @@ public class WriteLoops {
|
187
|
168
|
public int checkServerStatus() {
|
188
|
169
|
int w = 0;
|
189
|
170
|
String adminPhoneNumber = "+1 202 456 1111";
|
190
|
|
-
|
|
171
|
+ while (serverIsRunning() == true){
|
|
172
|
+ waitFor(5);
|
|
173
|
+ w = w + 1;
|
|
174
|
+ }
|
|
175
|
+ if (serverIsRunning() == false){
|
|
176
|
+ sendEmergencyText("Help!", adminPhoneNumber);
|
|
177
|
+ tryServerRestart("Try reset", adminPhoneNumber);
|
|
178
|
+ }
|
191
|
179
|
|
192
|
|
- // calling
|
193
|
|
- w = w + 1;
|
194
|
|
- // each time through the inner loop
|
195
|
|
-
|
196
|
180
|
return w;
|
197
|
181
|
}
|
198
|
182
|
|
|
@@ -201,12 +185,12 @@ public class WriteLoops {
|
201
|
185
|
// and if it is, add 7 to “i”
|
202
|
186
|
public int loop50by7() {
|
203
|
187
|
int w = 0;
|
204
|
|
-
|
205
|
|
-
|
206
|
|
- // calling
|
|
188
|
+ int i = 7;
|
|
189
|
+ while (i < 50){
|
|
190
|
+ i += 7;
|
207
|
191
|
w = w + 1;
|
208
|
|
- // each time through the inner loop
|
209
|
|
-
|
|
192
|
+
|
|
193
|
+ }
|
210
|
194
|
return w;
|
211
|
195
|
}
|
212
|
196
|
|
|
@@ -238,12 +222,10 @@ public class WriteLoops {
|
238
|
222
|
public int rewriteFooAsFor() {
|
239
|
223
|
int w = 0;
|
240
|
224
|
int sumOfThrees = 0;
|
241
|
|
-
|
242
|
|
-
|
243
|
|
- // calling
|
|
225
|
+ for (int i = 0; i < threes_array.length; i++){
|
|
226
|
+ sumOfThrees = sumOfThrees + threes_array[i];
|
244
|
227
|
w = w + 1;
|
245
|
|
- // each time through the inner loop
|
246
|
|
-
|
|
228
|
+ }
|
247
|
229
|
System.out.print("The Sum is ");
|
248
|
230
|
System.out.println(sumOfThrees);
|
249
|
231
|
|
|
@@ -255,12 +237,12 @@ public class WriteLoops {
|
255
|
237
|
public int rewriteFooAsWhile() {
|
256
|
238
|
int w = 0;
|
257
|
239
|
int sumOfThrees = 0;
|
|
240
|
+ int i = 0;
|
258
|
241
|
|
259
|
|
-
|
260
|
|
- // calling
|
|
242
|
+ while (i < threes_array.length){
|
|
243
|
+ sumOfThrees = sumOfThrees + threes_array[i];
|
261
|
244
|
w = w + 1;
|
262
|
|
- // each time through the inner loop
|
263
|
|
-
|
|
245
|
+ }
|
264
|
246
|
System.out.print("The Sum is ");
|
265
|
247
|
System.out.println(sumOfThrees);
|
266
|
248
|
|
|
@@ -277,13 +259,17 @@ public class WriteLoops {
|
277
|
259
|
public int manageYardAndJunior() {
|
278
|
260
|
int w = 0;
|
279
|
261
|
boolean onTime = true;
|
|
262
|
+ boolean yardNeedsMowed = true;
|
280
|
263
|
|
281
|
|
- // ADD YOUR CODE here.
|
282
|
|
-
|
283
|
|
- // be sure to call
|
|
264
|
+ while (isSummer() == true){
|
|
265
|
+ if (yardNeedsMowed == true){
|
|
266
|
+ yellAtJuniorToMowLawn();
|
|
267
|
+ }
|
284
|
268
|
w = w + 1;
|
285
|
|
- // each time inside the loop
|
286
|
|
-
|
|
269
|
+
|
|
270
|
+ }
|
|
271
|
+ sendJuniorBackToSchool("September 7, 2018");
|
|
272
|
+
|
287
|
273
|
return w;
|
288
|
274
|
}
|
289
|
275
|
|
|
@@ -295,12 +281,11 @@ public class WriteLoops {
|
295
|
281
|
public int tallyVote1() {
|
296
|
282
|
int w = 0;
|
297
|
283
|
int numberOfVotes = voteTallies.length;
|
298
|
|
-
|
299
|
|
-
|
300
|
|
- // calling
|
|
284
|
+ for (int i = 0; i <= numberOfVotes-1; i++){
|
|
285
|
+ System.out.println(voteTallies[i]);
|
301
|
286
|
w = w + 1;
|
302
|
287
|
// each time through the inner loop
|
303
|
|
-
|
|
288
|
+ }
|
304
|
289
|
return w;
|
305
|
290
|
}
|
306
|
291
|
|
|
@@ -309,13 +294,13 @@ public class WriteLoops {
|
309
|
294
|
// where you are.
|
310
|
295
|
public int tallyVote2() {
|
311
|
296
|
int w = 0;
|
|
297
|
+ int idx = 0;
|
312
|
298
|
int numberOfVotes = voteTallies.length;
|
313
|
|
-
|
314
|
|
-
|
315
|
|
- // calling
|
|
299
|
+ while (idx <= numberOfVotes-1){
|
|
300
|
+ System.out.println(voteTallies[idx]);
|
|
301
|
+ idx++;
|
316
|
302
|
w = w + 1;
|
317
|
|
- // each time through the inner loop
|
318
|
|
-
|
|
303
|
+ }
|
319
|
304
|
return w;
|
320
|
305
|
}
|
321
|
306
|
|
|
@@ -378,14 +363,15 @@ public class WriteLoops {
|
378
|
363
|
// return (i >= 3);
|
379
|
364
|
// };
|
380
|
365
|
// };
|
381
|
|
- private int summer = 0;
|
382
|
|
- private boolean isSummer() {
|
383
|
|
- if (summer == 3) {
|
384
|
|
- return true;
|
385
|
|
- }
|
386
|
|
- summer++;
|
387
|
|
- return false;
|
|
366
|
+ private int summer = 0;
|
|
367
|
+ private boolean isSummer() {
|
|
368
|
+ if (summer == 3) {
|
|
369
|
+ return true;
|
388
|
370
|
}
|
|
371
|
+ summer++;
|
|
372
|
+ return false;
|
|
373
|
+ }
|
|
374
|
+
|
389
|
375
|
private void sendEmergencyText(String mesg, String phone) {
|
390
|
376
|
}
|
391
|
377
|
|