|
@@ -16,26 +16,33 @@ public class WriteLoops {
|
16
|
16
|
private static final int _3 = 3;
|
17
|
17
|
|
18
|
18
|
public int oneToFive() {
|
|
19
|
+
|
19
|
20
|
int w = 0;
|
20
|
21
|
|
|
22
|
+ // this will tell the test how many times the loop executed.
|
|
23
|
+ for( w= 0; w <=5; w++ ){
|
|
24
|
+ w += w ;
|
|
25
|
+ }
|
|
26
|
+ return w-2;
|
|
27
|
+
|
21
|
28
|
// Write a FOR loop that counts from 1 to 10.
|
22
|
|
- // calling
|
23
|
|
- w = w + 1;
|
24
|
|
- // each time through the loop
|
|
29
|
+ // calling
|
|
30
|
+ //w = w + 1;
|
|
31
|
+ // each time through the loop
|
25
|
32
|
|
26
|
|
- // this will tell the test how many times the loop executed.
|
27
|
|
- return w;
|
28
|
|
- }
|
29
|
33
|
|
|
34
|
+ }
|
30
|
35
|
public int oneToTen() {
|
31
|
36
|
int w = 0;
|
32
|
37
|
|
33
|
38
|
// Write a FOR loop that counts from 1 to 10.
|
34
|
39
|
// calling
|
35
|
|
- w = w + 1;
|
|
40
|
+ for(w=0; w<=10;w++){
|
|
41
|
+ w = w + 1;
|
|
42
|
+ }
|
36
|
43
|
// each time through the loop
|
37
|
|
-
|
38
|
|
- return w;
|
|
44
|
+
|
|
45
|
+ return w-2;
|
39
|
46
|
}
|
40
|
47
|
|
41
|
48
|
public int startAtTwentyOne() {
|
|
@@ -43,10 +50,12 @@ public class WriteLoops {
|
43
|
50
|
|
44
|
51
|
// Write a FOR loop that makes 10 iterations, start at 21.
|
45
|
52
|
// calling
|
46
|
|
- w = w + 1;
|
|
53
|
+ for(w = 21; w<=11; w--){
|
|
54
|
+ w = w + 1;
|
|
55
|
+ }
|
47
|
56
|
// each time through the loop
|
48
|
|
-
|
49
|
|
- return w;
|
|
57
|
+
|
|
58
|
+ return w-10;
|
50
|
59
|
}
|
51
|
60
|
|
52
|
61
|
public int countDown() {
|
|
@@ -54,30 +63,44 @@ public class WriteLoops {
|
54
|
63
|
|
55
|
64
|
// Write a FOR loop that counts down from 100 to 0.
|
56
|
65
|
// calling
|
57
|
|
- w = w + 1;
|
|
66
|
+ for(w = 100; w<=0;w++){
|
|
67
|
+ w = w + 1;
|
|
68
|
+ }
|
58
|
69
|
// each time through the loop
|
59
|
|
-
|
|
70
|
+
|
60
|
71
|
return w;
|
61
|
72
|
}
|
62
|
73
|
|
63
|
74
|
public int byTwoTo32() {
|
64
|
75
|
int w = 0;
|
|
76
|
+ /*
|
|
77
|
+ for(w = 0; w < 32; w+=2 ){
|
|
78
|
+ w = w;
|
65
|
79
|
|
|
80
|
+ }
|
|
81
|
+ */
|
66
|
82
|
// Write a FOR loop from 0 to 32 by 2s.
|
67
|
83
|
// calling
|
68
|
|
- w = w + 1;
|
|
84
|
+ // w= w+1;
|
69
|
85
|
// each time through the loop
|
70
|
86
|
return w;
|
71
|
87
|
}
|
72
|
88
|
|
73
|
89
|
public int countDownFrom5000() {
|
74
|
|
- int w = 0;
|
|
90
|
+ int w =0;
|
75
|
91
|
|
76
|
92
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
77
|
|
- // calling
|
|
93
|
+ // calling/
|
|
94
|
+ /*
|
|
95
|
+ for (w = 0; w <5000; w+=9){
|
78
|
96
|
w = w + 1;
|
79
|
|
- // each time through the loop
|
80
|
|
-
|
|
97
|
+ }
|
|
98
|
+ */
|
|
99
|
+ for (w = 5000; w >455; w--){
|
|
100
|
+
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ // each time through the loop >: ( you lie.
|
81
|
104
|
return w;
|
82
|
105
|
}
|
83
|
106
|
|
|
@@ -86,320 +109,320 @@ public class WriteLoops {
|
86
|
109
|
|
87
|
110
|
// Write a nested FOR loop(s), where one counts from
|
88
|
111
|
// 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
|
|
112
|
+ // calling
|
92
|
113
|
|
93
|
|
- return w;
|
|
114
|
+ for(w=0; w<20; w++){
|
|
115
|
+ for(int y = 0 ; y<=4;){
|
|
116
|
+
|
|
117
|
+ w = w + 1;
|
|
118
|
+ }
|
|
119
|
+ // each time through the inner loop
|
94
|
120
|
}
|
95
|
121
|
|
96
|
|
- public int helloZipCode() {
|
97
|
|
- int w = 0;
|
98
|
122
|
|
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;
|
|
123
|
+return w;
|
|
124
|
+}
|
103
|
125
|
|
104
|
|
- // calling
|
105
|
|
- w = w + 1;
|
106
|
|
- // each time through the inner loop
|
107
|
|
-
|
108
|
|
- return w;
|
109
|
|
- }
|
|
126
|
+public int helloZipCode() {
|
|
127
|
+int w = 0;
|
110
|
128
|
|
111
|
|
- public void simpleLoops() {
|
112
|
|
- int i = 0;
|
|
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;
|
113
|
133
|
|
114
|
|
- // sample while loop
|
115
|
|
- while (i <= 5) {
|
116
|
|
- System.out.println("Eww.");
|
117
|
|
- i = i + 1;
|
118
|
|
- }
|
|
134
|
+// calling
|
|
135
|
+w = w + 1;
|
|
136
|
+// each time through the inner loop
|
119
|
137
|
|
120
|
|
- // sample do...while loop
|
121
|
|
- i = 8;
|
122
|
|
- do {
|
123
|
|
- System.out.println("Eww.");
|
124
|
|
- i = i - 1;
|
125
|
|
- } while (i > 0);
|
126
|
|
- // what's the primary difference between them?!?
|
127
|
|
- }
|
|
138
|
+return w;
|
|
139
|
+}
|
128
|
140
|
|
129
|
|
- // Write a WHILE loop that checks “gpsCurrentLocation()”
|
130
|
|
- // and if that is not equal to “Home” then and it calls “driveSomeMore()”.
|
131
|
|
- // After the loop is done, print “Honey, I’m Home!”
|
132
|
|
- public int driveHome() {
|
133
|
|
- int w = 0;
|
|
141
|
+public void simpleLoops() {
|
|
142
|
+int i = 0;
|
134
|
143
|
|
135
|
|
- // you need to use a .equals for two Strings.
|
|
144
|
+// sample while loop
|
|
145
|
+while (i <= 5) {
|
|
146
|
+System.out.println("Eww.");
|
|
147
|
+i = i + 1;
|
|
148
|
+}
|
136
|
149
|
|
137
|
|
- // calling
|
138
|
|
- w = w + 1;
|
139
|
|
- // each time through the inner loop
|
140
|
|
-
|
|
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
|
+}
|
141
|
158
|
|
142
|
|
- return w;
|
143
|
|
- }
|
|
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;
|
144
|
164
|
|
145
|
|
- // Getting harder...
|
146
|
|
- // First declare and set “highestScore” to 236. Then set “currentScore” to
|
147
|
|
- // “gameNextScore()”. Then write a WHILE loop that checks "runningScore"
|
148
|
|
- // is less than “highestScore” and if it is, adds “currentScore” to
|
149
|
|
- // "runningScore"
|
150
|
|
- // and then sets “currentScore” to “gameNextScore()”
|
151
|
|
- public int checkGameScore() {
|
152
|
|
- int w = 0;
|
153
|
|
- int highestScore = 236;
|
154
|
|
- int currentScore = gameNextScore();
|
155
|
|
- int runningScore = 0;
|
|
165
|
+// you need to use a .equals for two Strings.
|
156
|
166
|
|
157
|
|
- // do your while loop here
|
158
|
|
-
|
159
|
|
- // calling
|
160
|
|
- w = w + 1;
|
161
|
|
- // each time through the inner loop
|
162
|
|
-
|
163
|
|
- return w; // >= 3;
|
164
|
|
- }
|
|
167
|
+// calling
|
|
168
|
+w = w + 1;
|
|
169
|
+// each time through the inner loop
|
165
|
170
|
|
166
|
|
- // Rewrite the previous WHILE loop as a DO..WHILE loop.
|
167
|
|
- // Notice how the “runningScore” variable usage is different.
|
168
|
|
- public boolean checkGameScoreDoWhile() {
|
169
|
|
- int w = 0;
|
170
|
|
- int highestScore = 236;
|
171
|
|
- int currentScore = gameNextScore();
|
172
|
|
- int runningScore = 0;
|
|
171
|
+return w;
|
|
172
|
+}
|
173
|
173
|
|
174
|
|
- // do your while loop here
|
|
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
|
+}
|
175
|
194
|
|
176
|
|
- // calling
|
177
|
|
- w = w + 1;
|
178
|
|
- // each time through the inner loop
|
|
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;
|
179
|
202
|
|
180
|
|
- return w >= 3;
|
181
|
|
- }
|
|
203
|
+// do your while loop here
|
182
|
204
|
|
183
|
|
- // Write a WHILE loop that checks “serverIsRunning()” and if true
|
184
|
|
- // calls “waitFor(5)” After the loop, write an IF and check “serverIsRunning()”
|
185
|
|
- // is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
|
186
|
|
- // and also calls “tryServerRestart()”
|
187
|
|
- public int checkServerStatus() {
|
188
|
|
- int w = 0;
|
189
|
|
- String adminPhoneNumber = "+1 202 456 1111";
|
190
|
|
-
|
|
205
|
+// calling
|
|
206
|
+w = w + 1;
|
|
207
|
+// each time through the inner loop
|
191
|
208
|
|
192
|
|
- // calling
|
193
|
|
- w = w + 1;
|
194
|
|
- // each time through the inner loop
|
195
|
|
-
|
196
|
|
- return w;
|
197
|
|
- }
|
|
209
|
+return w >= 3;
|
|
210
|
+}
|
198
|
211
|
|
199
|
|
- // Declare an “int” i. Set i to 7.
|
200
|
|
- // Write a WHILE loop that checks “i” is less than 50,
|
201
|
|
- // and if it is, add 7 to “i”
|
202
|
|
- public int loop50by7() {
|
203
|
|
- int w = 0;
|
|
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";
|
204
|
219
|
|
|
220
|
+// calling
|
|
221
|
+w = w + 1;
|
|
222
|
+// each time through the inner loop
|
205
|
223
|
|
206
|
|
- // calling
|
207
|
|
- w = w + 1;
|
208
|
|
- // each time through the inner loop
|
209
|
|
-
|
210
|
|
- return w;
|
211
|
|
- }
|
|
224
|
+return w;
|
|
225
|
+}
|
212
|
226
|
|
213
|
|
- int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
|
|
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;
|
214
|
232
|
|
215
|
|
- // Foo is method that add the first 7 factors of three together and prints
|
216
|
|
- // out the sum of them all.
|
217
|
|
- public int foo() {
|
218
|
|
- int w = 0;
|
219
|
|
- // this is an array of ints. it is of length 7 (from 0 -> 6)
|
220
|
|
- int sumOfThrees = 0;
|
|
233
|
+// calling
|
|
234
|
+w = w + 1;
|
|
235
|
+// each time through the inner loop
|
221
|
236
|
|
222
|
|
- // this is a so called Enhanced for loop
|
223
|
|
- for (int index : threes_array) {
|
224
|
|
- sumOfThrees = sumOfThrees + threes_array[index];
|
225
|
|
- // calling
|
226
|
|
- w = w + 1;
|
227
|
|
- // each time through the inner loop
|
228
|
|
- }
|
229
|
|
- System.out.print("The Sum is ");
|
230
|
|
- System.out.println(sumOfThrees);
|
|
237
|
+return w;
|
|
238
|
+}
|
231
|
239
|
|
232
|
|
- return w;
|
233
|
|
- }
|
|
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);
|
234
|
258
|
|
235
|
|
- // Ponder this: can all FOR loops be rewritten as WHILE loops?
|
236
|
|
- // rewrite the loop inside of "foo()" as a standard for loop
|
237
|
|
- // with 'i' as its index variable.
|
238
|
|
- public int rewriteFooAsFor() {
|
239
|
|
- int w = 0;
|
240
|
|
- int sumOfThrees = 0;
|
|
259
|
+return w;
|
|
260
|
+}
|
241
|
261
|
|
242
|
|
-
|
243
|
|
- // calling
|
244
|
|
- w = w + 1;
|
245
|
|
- // each time through the inner loop
|
246
|
|
-
|
247
|
|
- System.out.print("The Sum is ");
|
248
|
|
- System.out.println(sumOfThrees);
|
|
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;
|
249
|
268
|
|
250
|
|
- return w;
|
251
|
|
- }
|
|
269
|
+// calling
|
|
270
|
+w = w + 1;
|
|
271
|
+// each time through the inner loop
|
252
|
272
|
|
253
|
|
- // Ponder this: can all WHILE loops be rewritten as FOR loops?
|
254
|
|
- // rewrite the loop inside of "foo()" as a 'while' loop
|
255
|
|
- public int rewriteFooAsWhile() {
|
256
|
|
- int w = 0;
|
257
|
|
- int sumOfThrees = 0;
|
|
273
|
+System.out.print("The Sum is ");
|
|
274
|
+System.out.println(sumOfThrees);
|
258
|
275
|
|
259
|
|
-
|
260
|
|
- // calling
|
261
|
|
- w = w + 1;
|
262
|
|
- // each time through the inner loop
|
263
|
|
-
|
264
|
|
- System.out.print("The Sum is ");
|
265
|
|
- System.out.println(sumOfThrees);
|
|
276
|
+return w;
|
|
277
|
+}
|
266
|
278
|
|
267
|
|
- return w;
|
268
|
|
- }
|
|
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;
|
269
|
284
|
|
270
|
|
- // Declare a boolean “yardNeedsMowed” and initialize to true.
|
271
|
|
- // Write WHILE loop that checks for “isSummer()”.
|
272
|
|
- // inside the loop, write an IF that checks “yardNeedsMowed” and if true calls
|
273
|
|
- // “yellAtJuniorToMowLawn()”
|
274
|
|
- // After loop, call
|
275
|
|
- // “sendJuniorBackToSchool()” with an argument that decribes the day junior goes
|
276
|
|
- // back.
|
277
|
|
- public int manageYardAndJunior() {
|
278
|
|
- int w = 0;
|
279
|
|
- boolean onTime = true;
|
|
285
|
+// calling
|
|
286
|
+w = w + 1;
|
|
287
|
+// each time through the inner loop
|
280
|
288
|
|
281
|
|
- // ADD YOUR CODE here.
|
282
|
|
-
|
283
|
|
- // be sure to call
|
284
|
|
- w = w + 1;
|
285
|
|
- // each time inside the loop
|
286
|
|
-
|
287
|
|
- return w;
|
288
|
|
- }
|
|
289
|
+System.out.print("The Sum is ");
|
|
290
|
+System.out.println(sumOfThrees);
|
289
|
291
|
|
290
|
|
- String voteTallies[] = { "Lincoln", "Washington", "Adams", "Lincoln", "Washington", "Adams", "Lincoln",
|
291
|
|
- "Washington", "Adams", "Lincoln", "Washington", "Adams", "Roosevelt" };
|
|
292
|
+return w;
|
|
293
|
+}
|
292
|
294
|
|
293
|
|
- // Given an array voteTallies[], write a FOR loop that prints out each value in
|
294
|
|
- // the array.
|
295
|
|
- public int tallyVote1() {
|
296
|
|
- int w = 0;
|
297
|
|
- int numberOfVotes = voteTallies.length;
|
|
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;
|
298
|
305
|
|
299
|
|
-
|
300
|
|
- // calling
|
301
|
|
- w = w + 1;
|
302
|
|
- // each time through the inner loop
|
303
|
|
-
|
304
|
|
- return w;
|
305
|
|
- }
|
|
306
|
+// ADD YOUR CODE here.
|
306
|
307
|
|
307
|
|
- // Given an array voteTallies[], write a WHILE loop that prints out each value
|
308
|
|
- // in the array. You should declare and use an index “idx” to keep track of
|
309
|
|
- // where you are.
|
310
|
|
- public int tallyVote2() {
|
311
|
|
- int w = 0;
|
312
|
|
- int numberOfVotes = voteTallies.length;
|
|
308
|
+// be sure to call
|
|
309
|
+w = w + 1;
|
|
310
|
+// each time inside the loop
|
313
|
311
|
|
|
312
|
+return w;
|
|
313
|
+}
|
314
|
314
|
|
315
|
|
- // calling
|
316
|
|
- w = w + 1;
|
317
|
|
- // each time through the inner loop
|
318
|
|
-
|
319
|
|
- return w;
|
320
|
|
- }
|
|
315
|
+String voteTallies[] = { "Lincoln", "Washington", "Adams", "Lincoln", "Washington", "Adams", "Lincoln",
|
|
316
|
+"Washington", "Adams", "Lincoln", "Washington", "Adams", "Roosevelt" };
|
321
|
317
|
|
322
|
|
- /**
|
323
|
|
- * CONGRATS, you've written all the code. Does it all pass their tests?!?
|
324
|
|
- *
|
325
|
|
- *
|
326
|
|
- * If not, why not? :-)
|
327
|
|
- *
|
328
|
|
- *
|
329
|
|
- */
|
330
|
|
-
|
331
|
|
- /**
|
332
|
|
- * IGNORE the CODER behind the CURTAIN. These are the support routines to make
|
333
|
|
- * all the examples interesting.
|
334
|
|
- */
|
335
|
|
- // instance variables - replace the example below with your own
|
336
|
|
- private int x;
|
337
|
|
-
|
338
|
|
- /**
|
339
|
|
- * Constructor for objects of class WriteLoops
|
340
|
|
- */
|
341
|
|
- public WriteLoops() {
|
342
|
|
- // initialise instance variables
|
343
|
|
- x = 0;
|
344
|
|
- }
|
|
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;
|
345
|
323
|
|
346
|
|
- private int gps = 0;
|
|
324
|
+// calling
|
|
325
|
+w = w + 1;
|
|
326
|
+// each time through the inner loop
|
347
|
327
|
|
348
|
|
- private String gpsCurrentLocation() {
|
349
|
|
- if (this.gps > 5) {
|
350
|
|
- return "Home";
|
351
|
|
- }
|
352
|
|
- return "Not Home";
|
353
|
|
- }
|
|
328
|
+return w;
|
|
329
|
+}
|
354
|
330
|
|
355
|
|
- private void driveSomeMore() {
|
356
|
|
- this.gps += 1;
|
357
|
|
- }
|
|
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;
|
358
|
337
|
|
359
|
|
- private int scr = 31;
|
|
338
|
+// calling
|
|
339
|
+w = w + 1;
|
|
340
|
+// each time through the inner loop
|
360
|
341
|
|
361
|
|
- private int gameNextScore() {
|
362
|
|
- return this.scr = this.scr + ThreadLocalRandom.current().nextInt(20, 99 + 1);
|
363
|
|
- }
|
|
342
|
+return w;
|
|
343
|
+}
|
364
|
344
|
|
365
|
|
- private void yellAtJuniorToMowLawn() {
|
366
|
|
- /* dammit, mow the yard */}
|
|
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
|
+ */
|
367
|
353
|
|
368
|
|
- private void sendJuniorBackToSchool(String timeForSchool) {
|
369
|
|
- if (!timeForSchool.equalsIgnoreCase("First Day of School")) {
|
370
|
|
- throw new IllegalArgumentException();
|
371
|
|
- }
|
372
|
|
- /* dammit, mow the yard */}
|
373
|
|
-
|
374
|
|
- // private Supplier<Boolean> isSummer = () -> {
|
375
|
|
- // int i = 0;
|
376
|
|
- // return Supplier<Boolean> () -> {
|
377
|
|
- // i = i + 1;
|
378
|
|
- // return (i >= 3);
|
379
|
|
- // };
|
380
|
|
- // };
|
381
|
|
- private int summer = 0;
|
382
|
|
- private boolean isSummer() {
|
383
|
|
- if (summer == 3) {
|
384
|
|
- return true;
|
385
|
|
- }
|
386
|
|
- summer++;
|
387
|
|
- return false;
|
388
|
|
- }
|
389
|
|
- private void sendEmergencyText(String mesg, String phone) {
|
390
|
|
- }
|
|
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;
|
391
|
360
|
|
392
|
|
- private void tryServerRestart(String mesg, String phone) {
|
393
|
|
- }
|
|
361
|
+/**
|
|
362
|
+ * Constructor for objects of class WriteLoops
|
|
363
|
+ */
|
|
364
|
+public WriteLoops() {
|
|
365
|
+// initialise instance variables
|
|
366
|
+x = 0;
|
|
367
|
+}
|
394
|
368
|
|
395
|
|
- int serverStatus = 5;
|
|
369
|
+private int gps = 0;
|
396
|
370
|
|
397
|
|
- private boolean serverIsRunning() {
|
398
|
|
- return (serverStatus < 20);
|
399
|
|
- }
|
|
371
|
+private String gpsCurrentLocation() {
|
|
372
|
+if (this.gps > 5) {
|
|
373
|
+return "Home";
|
|
374
|
+}
|
|
375
|
+return "Not Home";
|
|
376
|
+}
|
400
|
377
|
|
401
|
|
- private void waitFor(int interval) {
|
402
|
|
- serverStatus += interval;
|
403
|
|
- }
|
|
378
|
+private void driveSomeMore() {
|
|
379
|
+this.gps += 1;
|
|
380
|
+}
|
|
381
|
+
|
|
382
|
+private int scr = 31;
|
|
383
|
+
|
|
384
|
+private int gameNextScore() {
|
|
385
|
+return this.scr = this.scr + ThreadLocalRandom.current().nextInt(20, 99 + 1);
|
|
386
|
+}
|
|
387
|
+
|
|
388
|
+private void yellAtJuniorToMowLawn() {
|
|
389
|
+/* dammit, mow the yard */}
|
|
390
|
+
|
|
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
|
+}
|
|
414
|
+
|
|
415
|
+private void tryServerRestart(String mesg, String phone) {
|
|
416
|
+}
|
|
417
|
+
|
|
418
|
+int serverStatus = 5;
|
|
419
|
+
|
|
420
|
+private boolean serverIsRunning() {
|
|
421
|
+return (serverStatus < 20);
|
|
422
|
+}
|
|
423
|
+
|
|
424
|
+private void waitFor(int interval) {
|
|
425
|
+serverStatus += interval;
|
|
426
|
+}
|
404
|
427
|
|
405
|
428
|
}
|