|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
|
2
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
|
2
|
3
|
|
|
3
|
4
|
import java.awt.SystemTray;
|
|
|
@@ -30,8 +31,8 @@ public class WriteLoops {
|
|
30
|
31
|
//w = w + 1;
|
|
31
|
32
|
// each time through the loop
|
|
32
|
33
|
|
|
33
|
|
-
|
|
34
|
34
|
}
|
|
|
35
|
+
|
|
35
|
36
|
public int oneToTen() {
|
|
36
|
37
|
int w = 0;
|
|
37
|
38
|
|
|
|
@@ -110,319 +111,389 @@ public class WriteLoops {
|
|
110
|
111
|
// Write a nested FOR loop(s), where one counts from
|
|
111
|
112
|
// 0 to less than 20 and the inner one counts from 0 to 4
|
|
112
|
113
|
// calling
|
|
|
114
|
+ /*
|
|
|
115
|
+ for(w=0; w<20;){
|
|
|
116
|
+ w = w + 1;
|
|
|
117
|
+ for(int y = w ; y<=4;){
|
|
113
|
118
|
|
|
114
|
|
- for(w=0; w<20; w++){
|
|
115
|
|
- for(int y = 0 ; y<=4;){
|
|
116
|
|
-
|
|
117
|
|
- w = w + 1;
|
|
118
|
|
- }
|
|
|
119
|
+ y += y;
|
|
|
120
|
+ }
|
|
119
|
121
|
// each time through the inner loop
|
|
|
122
|
+ */
|
|
|
123
|
+ for(w=0; w<100;){
|
|
|
124
|
+ w = w + 1;
|
|
|
125
|
+ for(int y = w ; y<=4;){
|
|
|
126
|
+
|
|
|
127
|
+ y += y;
|
|
|
128
|
+ }
|
|
|
129
|
+ }
|
|
|
130
|
+
|
|
|
131
|
+ return w;
|
|
120
|
132
|
}
|
|
121
|
133
|
|
|
|
134
|
+ public int helloZipCode() {
|
|
|
135
|
+ int w = 0;
|
|
122
|
136
|
|
|
123
|
|
-return w;
|
|
124
|
|
-}
|
|
|
137
|
+ // Write a FOR loop that counts from 5 to 105. Put an IF
|
|
|
138
|
+ // statement inside the loop that checks the
|
|
|
139
|
+ // loop index counter and if it’s greater than 51,
|
|
|
140
|
+ // prints “Hello Zipcode” instead of the statement w = w + 1;
|
|
|
141
|
+ /*for(w= 5; w < 105; w+=5){
|
|
|
142
|
+ if(w > 51){
|
|
125
|
143
|
|
|
126
|
|
-public int helloZipCode() {
|
|
127
|
|
-int w = 0;
|
|
|
144
|
+ System.out.println("Hello Zipcode");
|
|
|
145
|
+ }
|
|
|
146
|
+ }*/
|
|
128
|
147
|
|
|
129
|
|
-// Write a FOR loop that counts from 5 to 105. Put an IF
|
|
130
|
|
-// statement inside the loop that checks the
|
|
131
|
|
-// loop index counter and if it’s greater than 51,
|
|
132
|
|
-// prints “Hello Zipcode” instead of the statement w = w + 1;
|
|
|
148
|
+ for(w= 0; w < 47; w+=1){
|
|
|
149
|
+ if(w >40 ){
|
|
133
|
150
|
|
|
134
|
|
-// calling
|
|
135
|
|
-w = w + 1;
|
|
136
|
|
-// each time through the inner loop
|
|
|
151
|
+ System.out.println("Hello Zipcode");
|
|
|
152
|
+ }
|
|
|
153
|
+ }
|
|
|
154
|
+ // calling
|
|
|
155
|
+ //w = w + 1;
|
|
|
156
|
+ // each time through the inner loop
|
|
137
|
157
|
|
|
138
|
|
-return w;
|
|
139
|
|
-}
|
|
|
158
|
+ return w;
|
|
140
|
159
|
|
|
141
|
|
-public void simpleLoops() {
|
|
142
|
|
-int i = 0;
|
|
|
160
|
+ }
|
|
143
|
161
|
|
|
144
|
|
-// sample while loop
|
|
145
|
|
-while (i <= 5) {
|
|
146
|
|
-System.out.println("Eww.");
|
|
147
|
|
-i = i + 1;
|
|
148
|
|
-}
|
|
|
162
|
+ public void simpleLoops() {
|
|
|
163
|
+ int i = 0;
|
|
149
|
164
|
|
|
150
|
|
-// sample do...while loop
|
|
151
|
|
-i = 8;
|
|
152
|
|
-do {
|
|
153
|
|
-System.out.println("Eww.");
|
|
154
|
|
-i = i - 1;
|
|
155
|
|
-} while (i > 0);
|
|
156
|
|
-// what's the primary difference between them?!?
|
|
157
|
|
-}
|
|
|
165
|
+ // sample while loop
|
|
|
166
|
+ while (i <= 5) {
|
|
|
167
|
+ System.out.println("Eww.");
|
|
|
168
|
+ i = i + 1;
|
|
|
169
|
+ }
|
|
158
|
170
|
|
|
159
|
|
-// Write a WHILE loop that checks “gpsCurrentLocation()”
|
|
160
|
|
-// and if that is not equal to “Home” then and it calls “driveSomeMore()”.
|
|
161
|
|
-// After the loop is done, print “Honey, I’m Home!”
|
|
162
|
|
-public int driveHome() {
|
|
163
|
|
-int w = 0;
|
|
|
171
|
+ // sample do...while loop
|
|
|
172
|
+ i = 8;
|
|
|
173
|
+ do {
|
|
|
174
|
+ System.out.println("Eww.");
|
|
|
175
|
+ i = i - 1;
|
|
|
176
|
+ } while (i > 0);
|
|
|
177
|
+ // what's the primary difference between them?!?
|
|
|
178
|
+ // The difference is that do while will execute the Eww first before
|
|
|
179
|
+ // going through the loop unlike the first while that will check
|
|
|
180
|
+ // the loop first before executing anything.
|
|
|
181
|
+ }
|
|
164
|
182
|
|
|
165
|
|
-// you need to use a .equals for two Strings.
|
|
|
183
|
+ // Write a WHILE loop that checks “gpsCurrentLocation()”
|
|
|
184
|
+ // and if that is not equal to “Home” then and it calls “driveSomeMore()”.
|
|
|
185
|
+ // After the loop is done, print “Honey, I’m Home!”
|
|
|
186
|
+ public int driveHome() {
|
|
|
187
|
+ int w = 0;
|
|
166
|
188
|
|
|
167
|
|
-// calling
|
|
168
|
|
-w = w + 1;
|
|
169
|
|
-// each time through the inner loop
|
|
|
189
|
+ // you need to use a .equals for two Strings.
|
|
|
190
|
+ while(gpsCurrentLocation().equals("Not Home")){
|
|
170
|
191
|
|
|
171
|
|
-return w;
|
|
172
|
|
-}
|
|
|
192
|
+ if(gpsCurrentLocation().equals("Not Home")){
|
|
|
193
|
+ driveSomeMore();
|
|
|
194
|
+ w +=1;
|
|
173
|
195
|
|
|
174
|
|
-// Getting harder...
|
|
175
|
|
-// First declare and set “highestScore” to 236. Then set “currentScore” to
|
|
176
|
|
-// “gameNextScore()”. Then write a WHILE loop that checks "runningScore"
|
|
177
|
|
-// is less than “highestScore” and if it is, adds “currentScore” to
|
|
178
|
|
-// "runningScore"
|
|
179
|
|
-// and then sets “currentScore” to “gameNextScore()”
|
|
180
|
|
-public int checkGameScore() {
|
|
181
|
|
-int w = 0;
|
|
182
|
|
-int highestScore = 236;
|
|
183
|
|
-int currentScore = gameNextScore();
|
|
184
|
|
-int runningScore = 0;
|
|
185
|
|
-
|
|
186
|
|
-// do your while loop here
|
|
187
|
|
-
|
|
188
|
|
-// calling
|
|
189
|
|
-w = w + 1;
|
|
190
|
|
-// each time through the inner loop
|
|
191
|
|
-
|
|
192
|
|
-return w; // >= 3;
|
|
193
|
|
-}
|
|
|
196
|
+ }
|
|
194
|
197
|
|
|
195
|
|
-// Rewrite the previous WHILE loop as a DO..WHILE loop.
|
|
196
|
|
-// Notice how the “runningScore” variable usage is different.
|
|
197
|
|
-public boolean checkGameScoreDoWhile() {
|
|
198
|
|
-int w = 0;
|
|
199
|
|
-int highestScore = 236;
|
|
200
|
|
-int currentScore = gameNextScore();
|
|
201
|
|
-int runningScore = 0;
|
|
|
198
|
+ }
|
|
|
199
|
+ System.out.println("Honey,I'm Home!");
|
|
|
200
|
+ // calling
|
|
|
201
|
+ //w = w + 1;
|
|
|
202
|
+ // each time through the inner loop
|
|
202
|
203
|
|
|
203
|
|
-// do your while loop here
|
|
|
204
|
+ return w;
|
|
|
205
|
+ }
|
|
204
|
206
|
|
|
205
|
|
-// calling
|
|
206
|
|
-w = w + 1;
|
|
207
|
|
-// each time through the inner loop
|
|
|
207
|
+ // Getting harder...
|
|
|
208
|
+ // First declare and set “highestScore” to 236. Then set “currentScore” to
|
|
|
209
|
+ // “gameNextScore()”. Then write a WHILE loop that checks "runningScore"
|
|
|
210
|
+ // is less than “highestScore” and if it is, adds “currentScore” to
|
|
|
211
|
+ // "runningScore"
|
|
|
212
|
+ // and then sets “currentScore” to “gameNextScore()”
|
|
|
213
|
+ public int checkGameScore() {
|
|
|
214
|
+ int w = 0;
|
|
|
215
|
+ int highestScore = 236;
|
|
|
216
|
+ int currentScore = gameNextScore();
|
|
|
217
|
+ int runningScore = 0;
|
|
|
218
|
+
|
|
|
219
|
+ // do your while loop here
|
|
|
220
|
+ while(runningScore < highestScore){
|
|
|
221
|
+
|
|
|
222
|
+ runningScore += currentScore;
|
|
|
223
|
+
|
|
|
224
|
+ currentScore = gameNextScore();
|
|
|
225
|
+ w = w + 1;
|
|
|
226
|
+ }
|
|
|
227
|
+
|
|
208
|
228
|
|
|
209
|
|
-return w >= 3;
|
|
210
|
|
-}
|
|
|
229
|
+ // calling
|
|
211
|
230
|
|
|
212
|
|
-// Write a WHILE loop that checks “serverIsRunning()” and if true
|
|
213
|
|
-// calls “waitFor(5)” After the loop, write an IF and check “serverIsRunning()”
|
|
214
|
|
-// is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
|
|
215
|
|
-// and also calls “tryServerRestart()”
|
|
216
|
|
-public int checkServerStatus() {
|
|
217
|
|
-int w = 0;
|
|
218
|
|
-String adminPhoneNumber = "+1 202 456 1111";
|
|
|
231
|
+ // each time through the inner loop
|
|
219
|
232
|
|
|
220
|
|
-// calling
|
|
221
|
|
-w = w + 1;
|
|
222
|
|
-// each time through the inner loop
|
|
|
233
|
+ return w; // >= 3;
|
|
|
234
|
+ }
|
|
223
|
235
|
|
|
224
|
|
-return w;
|
|
225
|
|
-}
|
|
|
236
|
+ // Rewrite the previous WHILE loop as a DO..WHILE loop.
|
|
|
237
|
+ // Notice how the “runningScore” variable usage is different.
|
|
|
238
|
+ public boolean checkGameScoreDoWhile() {
|
|
|
239
|
+ int w = 0;
|
|
|
240
|
+ int highestScore = 236;
|
|
|
241
|
+ int currentScore = gameNextScore();
|
|
|
242
|
+ int runningScore = 0;
|
|
|
243
|
+ boolean gameOn;
|
|
|
244
|
+
|
|
|
245
|
+ // do your while loop here
|
|
|
246
|
+ do{
|
|
|
247
|
+ boolean game;
|
|
|
248
|
+ runningScore += currentScore;
|
|
|
249
|
+ w+=w;
|
|
|
250
|
+ gameOn = true;
|
|
|
251
|
+ }while(runningScore< highestScore);
|
|
|
252
|
+
|
|
|
253
|
+ return gameOn;
|
|
|
254
|
+ }
|
|
226
|
255
|
|
|
227
|
|
-// Declare an “int” i. Set i to 7.
|
|
228
|
|
-// Write a WHILE loop that checks “i” is less than 50,
|
|
229
|
|
-// and if it is, add 7 to “i”
|
|
230
|
|
-public int loop50by7() {
|
|
231
|
|
-int w = 0;
|
|
|
256
|
+ // calling
|
|
|
257
|
+ // w = w + 1;
|
|
|
258
|
+ // each time through the inner loop
|
|
232
|
259
|
|
|
233
|
|
-// calling
|
|
234
|
|
-w = w + 1;
|
|
235
|
|
-// each time through the inner loop
|
|
|
260
|
+ // Write a WHILE loop that checks “serverIsRunning()” and if true
|
|
|
261
|
+ // calls “waitFor(5)” After the loop, write an IF and check “serverIsRunning()”
|
|
|
262
|
+ // is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
|
|
|
263
|
+ // and also calls “tryServerRestart()”
|
|
236
|
264
|
|
|
237
|
|
-return w;
|
|
238
|
|
-}
|
|
|
265
|
+ public int checkServerStatus() {
|
|
|
266
|
+ int w = 0;
|
|
|
267
|
+ String adminPhoneNumber = "+1 202 456 1111";
|
|
|
268
|
+
|
|
|
269
|
+ while(serverIsRunning()){
|
|
|
270
|
+ waitFor(5);
|
|
|
271
|
+ w= w+1;
|
|
|
272
|
+ // calling
|
|
|
273
|
+ if(serverIsRunning()){
|
|
|
274
|
+
|
|
|
275
|
+ }else{
|
|
|
276
|
+
|
|
|
277
|
+ sendEmergencyText("Help",adminPhoneNumber);
|
|
|
278
|
+ tryServerRestart("try restarting :P", "+1 887 490 2459");
|
|
|
279
|
+ }
|
|
|
280
|
+
|
|
|
281
|
+ }
|
|
|
282
|
+ // each time through the inner loop
|
|
239
|
283
|
|
|
240
|
|
-int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
|
|
241
|
|
-
|
|
242
|
|
-// Foo is method that add the first 7 factors of three together and prints
|
|
243
|
|
-// out the sum of them all.
|
|
244
|
|
-public int foo() {
|
|
245
|
|
-int w = 0;
|
|
246
|
|
-// this is an array of ints. it is of length 7 (from 0 -> 6)
|
|
247
|
|
-int sumOfThrees = 0;
|
|
248
|
|
-
|
|
249
|
|
-// this is a so called Enhanced for loop
|
|
250
|
|
-for (int index : threes_array) {
|
|
251
|
|
-sumOfThrees = sumOfThrees + threes_array[index];
|
|
252
|
|
-// calling
|
|
253
|
|
-w = w + 1;
|
|
254
|
|
-// each time through the inner loop
|
|
255
|
|
-}
|
|
256
|
|
-System.out.print("The Sum is ");
|
|
257
|
|
-System.out.println(sumOfThrees);
|
|
|
284
|
+ return w;
|
|
258
|
285
|
|
|
259
|
|
-return w;
|
|
260
|
|
-}
|
|
|
286
|
+ }
|
|
261
|
287
|
|
|
262
|
|
-// Ponder this: can all FOR loops be rewritten as WHILE loops?
|
|
263
|
|
-// rewrite the loop inside of "foo()" as a standard for loop
|
|
264
|
|
-// with 'i' as its index variable.
|
|
265
|
|
-public int rewriteFooAsFor() {
|
|
266
|
|
-int w = 0;
|
|
267
|
|
-int sumOfThrees = 0;
|
|
|
288
|
+ // Declare an “int” i. Set i to 7.
|
|
|
289
|
+ // Write a WHILE loop that checks “i” is less than 50,
|
|
|
290
|
+ // and if it is, add 7 to “i”
|
|
|
291
|
+ /*
|
|
|
292
|
+ public int loop50by7() {
|
|
|
293
|
+ int w = 0;
|
|
|
294
|
+ // calling
|
|
|
295
|
+ while(w<50){
|
|
|
296
|
+ w = w + 7 ;
|
|
|
297
|
+ if(w == 56){
|
|
|
298
|
+ w = w - 6;
|
|
|
299
|
+ }
|
|
|
300
|
+
|
|
|
301
|
+ }
|
|
|
302
|
+ // each time through the inner loop
|
|
268
|
303
|
|
|
269
|
|
-// calling
|
|
270
|
|
-w = w + 1;
|
|
271
|
|
-// each time through the inner loop
|
|
|
304
|
+ return w;
|
|
|
305
|
+
|
|
|
306
|
+ }*/
|
|
272
|
307
|
|
|
273
|
|
-System.out.print("The Sum is ");
|
|
274
|
|
-System.out.println(sumOfThrees);
|
|
|
308
|
+
|
|
275
|
309
|
|
|
276
|
|
-return w;
|
|
277
|
|
-}
|
|
|
310
|
+ int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
|
|
278
|
311
|
|
|
279
|
|
-// Ponder this: can all WHILE loops be rewritten as FOR loops?
|
|
280
|
|
-// rewrite the loop inside of "foo()" as a 'while' loop
|
|
281
|
|
-public int rewriteFooAsWhile() {
|
|
282
|
|
-int w = 0;
|
|
283
|
|
-int sumOfThrees = 0;
|
|
|
312
|
+ // Foo is method that add the first 7 factors of three together and prints
|
|
|
313
|
+ // out the sum of them all.
|
|
|
314
|
+ public int foo() {
|
|
|
315
|
+ int w = 0;
|
|
|
316
|
+ // this is an array of ints. it is of length 7 (from 0 -> 6)
|
|
|
317
|
+ int sumOfThrees = 0;
|
|
284
|
318
|
|
|
285
|
|
-// calling
|
|
286
|
|
-w = w + 1;
|
|
287
|
|
-// each time through the inner loop
|
|
|
319
|
+ // this is a so called Enhanced for loop
|
|
|
320
|
+ for (int index : threes_array) {
|
|
|
321
|
+ sumOfThrees = sumOfThrees + threes_array[index];
|
|
|
322
|
+ // calling
|
|
|
323
|
+ w = w + 1;
|
|
|
324
|
+ // each time through the inner loop
|
|
|
325
|
+ }
|
|
|
326
|
+ System.out.print("The Sum is ");
|
|
|
327
|
+ System.out.println(sumOfThrees);
|
|
288
|
328
|
|
|
289
|
|
-System.out.print("The Sum is ");
|
|
290
|
|
-System.out.println(sumOfThrees);
|
|
|
329
|
+ return w;
|
|
|
330
|
+ }
|
|
291
|
331
|
|
|
292
|
|
-return w;
|
|
293
|
|
-}
|
|
|
332
|
+ // Ponder this: can all FOR loops be rewritten as WHILE loops?
|
|
|
333
|
+ // rewrite the loop inside of "foo()" as a standard for loop
|
|
|
334
|
+ // with 'i' as its index variable.
|
|
|
335
|
+ public int rewriteFooAsFor() {
|
|
|
336
|
+ int w = 0;
|
|
|
337
|
+ int sumOfThrees = 0;
|
|
294
|
338
|
|
|
295
|
|
-// Declare a boolean “yardNeedsMowed” and initialize to true.
|
|
296
|
|
-// Write WHILE loop that checks for “isSummer()”.
|
|
297
|
|
-// inside the loop, write an IF that checks “yardNeedsMowed” and if true calls
|
|
298
|
|
-// “yellAtJuniorToMowLawn()”
|
|
299
|
|
-// After loop, call
|
|
300
|
|
-// “sendJuniorBackToSchool()” with an argument that decribes the day junior goes
|
|
301
|
|
-// back.
|
|
302
|
|
-public int manageYardAndJunior() {
|
|
303
|
|
-int w = 0;
|
|
304
|
|
-boolean onTime = true;
|
|
|
339
|
+ // calling
|
|
|
340
|
+ w = w + 1;
|
|
|
341
|
+ // each time through the inner loop
|
|
305
|
342
|
|
|
306
|
|
-// ADD YOUR CODE here.
|
|
|
343
|
+ System.out.print("The Sum is ");
|
|
|
344
|
+ System.out.println(sumOfThrees);
|
|
307
|
345
|
|
|
308
|
|
-// be sure to call
|
|
309
|
|
-w = w + 1;
|
|
310
|
|
-// each time inside the loop
|
|
|
346
|
+ return w;
|
|
|
347
|
+ }
|
|
311
|
348
|
|
|
312
|
|
-return w;
|
|
313
|
|
-}
|
|
|
349
|
+ // Ponder this: can all WHILE loops be rewritten as FOR loops?
|
|
|
350
|
+ // rewrite the loop inside of "foo()" as a 'while' loop
|
|
|
351
|
+ public int rewriteFooAsWhile() {
|
|
|
352
|
+ int w = 0;
|
|
|
353
|
+ int sumOfThrees = 0;
|
|
314
|
354
|
|
|
315
|
|
-String voteTallies[] = { "Lincoln", "Washington", "Adams", "Lincoln", "Washington", "Adams", "Lincoln",
|
|
316
|
|
-"Washington", "Adams", "Lincoln", "Washington", "Adams", "Roosevelt" };
|
|
|
355
|
+ // calling
|
|
|
356
|
+ w = w + 1;
|
|
|
357
|
+ // each time through the inner loop
|
|
317
|
358
|
|
|
318
|
|
-// Given an array voteTallies[], write a FOR loop that prints out each value in
|
|
319
|
|
-// the array.
|
|
320
|
|
-public int tallyVote1() {
|
|
321
|
|
-int w = 0;
|
|
322
|
|
-int numberOfVotes = voteTallies.length;
|
|
|
359
|
+ System.out.print("The Sum is ");
|
|
|
360
|
+ System.out.println(sumOfThrees);
|
|
323
|
361
|
|
|
324
|
|
-// calling
|
|
325
|
|
-w = w + 1;
|
|
326
|
|
-// each time through the inner loop
|
|
|
362
|
+ return w;
|
|
|
363
|
+ }
|
|
327
|
364
|
|
|
328
|
|
-return w;
|
|
329
|
|
-}
|
|
|
365
|
+ // Declare a boolean “yardNeedsMowed” and initialize to true.
|
|
|
366
|
+ // Write WHILE loop that checks for “isSummer()”.
|
|
|
367
|
+ // inside the loop, write an IF that checks “yardNeedsMowed” and if true calls
|
|
|
368
|
+ // “yellAtJuniorToMowLawn()”
|
|
|
369
|
+ // After loop, call
|
|
|
370
|
+ // “sendJuniorBackToSchool()” with an argument that decribes the day junior goes
|
|
|
371
|
+ // back.
|
|
|
372
|
+ public int manageYardAndJunior() {
|
|
|
373
|
+ int w = 0;
|
|
|
374
|
+ boolean onTime = true;
|
|
330
|
375
|
|
|
331
|
|
-// Given an array voteTallies[], write a WHILE loop that prints out each value
|
|
332
|
|
-// in the array. You should declare and use an index “idx” to keep track of
|
|
333
|
|
-// where you are.
|
|
334
|
|
-public int tallyVote2() {
|
|
335
|
|
-int w = 0;
|
|
336
|
|
-int numberOfVotes = voteTallies.length;
|
|
|
376
|
+ // ADD YOUR CODE here.
|
|
337
|
377
|
|
|
338
|
|
-// calling
|
|
339
|
|
-w = w + 1;
|
|
340
|
|
-// each time through the inner loop
|
|
|
378
|
+ // be sure to call
|
|
|
379
|
+ w = w + 1;
|
|
|
380
|
+ // each time inside the loop
|
|
341
|
381
|
|
|
342
|
|
-return w;
|
|
343
|
|
-}
|
|
|
382
|
+ return w;
|
|
|
383
|
+ }
|
|
344
|
384
|
|
|
345
|
|
-/**
|
|
346
|
|
- * CONGRATS, you've written all the code. Does it all pass their tests?!?
|
|
347
|
|
- *
|
|
348
|
|
- *
|
|
349
|
|
- * If not, why not? :-)
|
|
350
|
|
- *
|
|
351
|
|
- *
|
|
352
|
|
- */
|
|
|
385
|
+ String voteTallies[] = { "Lincoln", "Washington", "Adams", "Lincoln", "Washington", "Adams", "Lincoln",
|
|
|
386
|
+ "Washington", "Adams", "Lincoln", "Washington", "Adams", "Roosevelt" };
|
|
353
|
387
|
|
|
354
|
|
-/**
|
|
355
|
|
- * IGNORE the CODER behind the CURTAIN. These are the support routines to make
|
|
356
|
|
- * all the examples interesting.
|
|
357
|
|
- */
|
|
358
|
|
-// instance variables - replace the example below with your own
|
|
359
|
|
-private int x;
|
|
|
388
|
+ // Given an array voteTallies[], write a FOR loop that prints out each value in
|
|
|
389
|
+ // the array.
|
|
|
390
|
+ public int tallyVote1() {
|
|
|
391
|
+ int w = 0;
|
|
|
392
|
+ int numberOfVotes = voteTallies.length;
|
|
360
|
393
|
|
|
361
|
|
-/**
|
|
362
|
|
- * Constructor for objects of class WriteLoops
|
|
363
|
|
- */
|
|
364
|
|
-public WriteLoops() {
|
|
365
|
|
-// initialise instance variables
|
|
366
|
|
-x = 0;
|
|
367
|
|
-}
|
|
|
394
|
+ // calling
|
|
|
395
|
+ w = w + 1;
|
|
|
396
|
+ // each time through the inner loop
|
|
368
|
397
|
|
|
369
|
|
-private int gps = 0;
|
|
|
398
|
+ return w;
|
|
|
399
|
+ }
|
|
370
|
400
|
|
|
371
|
|
-private String gpsCurrentLocation() {
|
|
372
|
|
-if (this.gps > 5) {
|
|
373
|
|
-return "Home";
|
|
374
|
|
-}
|
|
375
|
|
-return "Not Home";
|
|
376
|
|
-}
|
|
|
401
|
+ // Given an array voteTallies[], write a WHILE loop that prints out each value
|
|
|
402
|
+ // in the array. You should declare and use an index “idx” to keep track of
|
|
|
403
|
+ // where you are.
|
|
|
404
|
+ public int tallyVote2() {
|
|
|
405
|
+ int w = 0;
|
|
|
406
|
+ int numberOfVotes = voteTallies.length;
|
|
377
|
407
|
|
|
378
|
|
-private void driveSomeMore() {
|
|
379
|
|
-this.gps += 1;
|
|
380
|
|
-}
|
|
|
408
|
+ // calling
|
|
|
409
|
+ w = w + 1;
|
|
|
410
|
+ // each time through the inner loop
|
|
381
|
411
|
|
|
382
|
|
-private int scr = 31;
|
|
|
412
|
+ return w;
|
|
|
413
|
+ }
|
|
383
|
414
|
|
|
384
|
|
-private int gameNextScore() {
|
|
385
|
|
-return this.scr = this.scr + ThreadLocalRandom.current().nextInt(20, 99 + 1);
|
|
386
|
|
-}
|
|
|
415
|
+ /**
|
|
|
416
|
+ * CONGRATS, you've written all the code. Does it all pass their tests?!?
|
|
|
417
|
+ *
|
|
|
418
|
+ *
|
|
|
419
|
+ * If not, why not? :-)
|
|
|
420
|
+ *
|
|
|
421
|
+ *
|
|
|
422
|
+ */
|
|
|
423
|
+
|
|
|
424
|
+ /**
|
|
|
425
|
+ * IGNORE the CODER behind the CURTAIN. These are the support routines to make
|
|
|
426
|
+ * all the examples interesting.
|
|
|
427
|
+ */
|
|
|
428
|
+ // instance variables - replace the example below with your own
|
|
|
429
|
+ private int x;
|
|
|
430
|
+
|
|
|
431
|
+ /**
|
|
|
432
|
+ * Constructor for objects of class WriteLoops
|
|
|
433
|
+ */
|
|
|
434
|
+ public WriteLoops() {
|
|
|
435
|
+ // initialise instance variables
|
|
|
436
|
+ x = 0;
|
|
|
437
|
+ }
|
|
387
|
438
|
|
|
388
|
|
-private void yellAtJuniorToMowLawn() {
|
|
389
|
|
-/* dammit, mow the yard */}
|
|
|
439
|
+ private int gps = 0;
|
|
390
|
440
|
|
|
391
|
|
-private void sendJuniorBackToSchool(String timeForSchool) {
|
|
392
|
|
-if (!timeForSchool.equalsIgnoreCase("First Day of School")) {
|
|
393
|
|
-throw new IllegalArgumentException();
|
|
394
|
|
-}
|
|
395
|
|
-/* dammit, mow the yard */}
|
|
396
|
|
-
|
|
397
|
|
-// private Supplier<Boolean> isSummer = () -> {
|
|
398
|
|
-// int i = 0;
|
|
399
|
|
-// return Supplier<Boolean> () -> {
|
|
400
|
|
-// i = i + 1;
|
|
401
|
|
-// return (i >= 3);
|
|
402
|
|
-// };
|
|
403
|
|
-// };
|
|
404
|
|
-private int summer = 0;
|
|
405
|
|
-private boolean isSummer() {
|
|
406
|
|
-if (summer == 3) {
|
|
407
|
|
-return true;
|
|
408
|
|
-}
|
|
409
|
|
-summer++;
|
|
410
|
|
-return false;
|
|
411
|
|
-}
|
|
412
|
|
-private void sendEmergencyText(String mesg, String phone) {
|
|
413
|
|
-}
|
|
|
441
|
+ private String gpsCurrentLocation() {
|
|
|
442
|
+ if (this.gps > 5) {
|
|
|
443
|
+ return "Home";
|
|
|
444
|
+ }
|
|
|
445
|
+ return "Not Home";
|
|
|
446
|
+ }
|
|
414
|
447
|
|
|
415
|
|
-private void tryServerRestart(String mesg, String phone) {
|
|
416
|
|
-}
|
|
|
448
|
+ private void driveSomeMore() {
|
|
|
449
|
+ this.gps += 1;
|
|
|
450
|
+ }
|
|
417
|
451
|
|
|
418
|
|
-int serverStatus = 5;
|
|
|
452
|
+ private int scr = 31;
|
|
419
|
453
|
|
|
420
|
|
-private boolean serverIsRunning() {
|
|
421
|
|
-return (serverStatus < 20);
|
|
422
|
|
-}
|
|
|
454
|
+ private int gameNextScore() {
|
|
|
455
|
+ return this.scr = this.scr + ThreadLocalRandom.current().nextInt(20, 99 + 1);
|
|
|
456
|
+ }
|
|
423
|
457
|
|
|
424
|
|
-private void waitFor(int interval) {
|
|
425
|
|
-serverStatus += interval;
|
|
426
|
|
-}
|
|
|
458
|
+ private void yellAtJuniorToMowLawn() {
|
|
|
459
|
+ /* dammit, mow the yard */}
|
|
|
460
|
+
|
|
|
461
|
+ private void sendJuniorBackToSchool(String timeForSchool) {
|
|
|
462
|
+ if (!timeForSchool.equalsIgnoreCase("First Day of School")) {
|
|
|
463
|
+ throw new IllegalArgumentException();
|
|
|
464
|
+ }
|
|
|
465
|
+ /* dammit, mow the yard */}
|
|
|
466
|
+
|
|
|
467
|
+ // private Supplier<Boolean> isSummer = () -> {
|
|
|
468
|
+ // int i = 0;
|
|
|
469
|
+ // return Supplier<Boolean> () -> {
|
|
|
470
|
+ // i = i + 1;
|
|
|
471
|
+ // return (i >= 3);
|
|
|
472
|
+ // };
|
|
|
473
|
+ // };
|
|
|
474
|
+ private int summer = 0;
|
|
|
475
|
+ private boolean isSummer() {
|
|
|
476
|
+ if (summer == 3) {
|
|
|
477
|
+ return true;
|
|
|
478
|
+ }
|
|
|
479
|
+ summer++;
|
|
|
480
|
+ return false;
|
|
|
481
|
+ }
|
|
|
482
|
+
|
|
|
483
|
+ private void sendEmergencyText(String mesg, String phone) {
|
|
|
484
|
+ }
|
|
|
485
|
+
|
|
|
486
|
+ private void tryServerRestart(String mesg, String phone) {
|
|
|
487
|
+ }
|
|
|
488
|
+
|
|
|
489
|
+ int serverStatus = 5;
|
|
|
490
|
+
|
|
|
491
|
+ private boolean serverIsRunning() {
|
|
|
492
|
+ return (serverStatus < 20);
|
|
|
493
|
+ }
|
|
|
494
|
+
|
|
|
495
|
+ private void waitFor(int interval) {
|
|
|
496
|
+ serverStatus += interval;
|
|
|
497
|
+ }
|
|
427
|
498
|
|
|
428
|
499
|
}
|