|
@@ -1,5 +1,5 @@
|
1
|
1
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
2
|
|
-
|
|
2
|
+import java.lang.String;
|
3
|
3
|
import java.awt.SystemTray;
|
4
|
4
|
import java.util.concurrent.ThreadLocalRandom;
|
5
|
5
|
import java.util.function.Supplier;
|
|
@@ -17,10 +17,12 @@ public class WriteLoops {
|
17
|
17
|
|
18
|
18
|
public int oneToFive() {
|
19
|
19
|
int w = 0;
|
20
|
|
-
|
|
20
|
+ for(int i = 1; i <= 5;i++){
|
|
21
|
+ w++;
|
|
22
|
+ }
|
21
|
23
|
// Write a FOR loop that counts from 1 to 10.
|
22
|
24
|
// calling
|
23
|
|
- w = w + 1;
|
|
25
|
+
|
24
|
26
|
// each time through the loop
|
25
|
27
|
|
26
|
28
|
// this will tell the test how many times the loop executed.
|
|
@@ -29,10 +31,12 @@ public class WriteLoops {
|
29
|
31
|
|
30
|
32
|
public int oneToTen() {
|
31
|
33
|
int w = 0;
|
32
|
|
-
|
|
34
|
+ for(int i = 1; i <= 10; i++){
|
|
35
|
+ w++;
|
|
36
|
+ }
|
33
|
37
|
// Write a FOR loop that counts from 1 to 10.
|
34
|
38
|
// calling
|
35
|
|
- w = w + 1;
|
|
39
|
+
|
36
|
40
|
// each time through the loop
|
37
|
41
|
|
38
|
42
|
return w;
|
|
@@ -40,21 +44,30 @@ public class WriteLoops {
|
40
|
44
|
|
41
|
45
|
public int startAtTwentyOne() {
|
42
|
46
|
int w = 0;
|
43
|
|
-
|
|
47
|
+
|
|
48
|
+ for(int i = 21; i <= 31; i++){
|
|
49
|
+ w++;
|
|
50
|
+
|
|
51
|
+ }
|
44
|
52
|
// Write a FOR loop that makes 10 iterations, start at 21.
|
45
|
53
|
// calling
|
46
|
|
- w = w + 1;
|
|
54
|
+
|
47
|
55
|
// each time through the loop
|
48
|
56
|
|
|
57
|
+
|
|
58
|
+
|
49
|
59
|
return w;
|
50
|
60
|
}
|
51
|
61
|
|
52
|
62
|
public int countDown() {
|
53
|
63
|
int w = 0;
|
54
|
|
-
|
|
64
|
+
|
|
65
|
+ for(int i = 100; i > 0; i--){
|
|
66
|
+ w++;
|
|
67
|
+ }
|
55
|
68
|
// Write a FOR loop that counts down from 100 to 0.
|
56
|
69
|
// calling
|
57
|
|
- w = w + 1;
|
|
70
|
+
|
58
|
71
|
// each time through the loop
|
59
|
72
|
|
60
|
73
|
return w;
|
|
@@ -62,32 +75,48 @@ public class WriteLoops {
|
62
|
75
|
|
63
|
76
|
public int byTwoTo32() {
|
64
|
77
|
int w = 0;
|
65
|
|
-
|
66
|
|
- // Write a FOR loop from 0 to 32 by 2s.
|
67
|
|
- // calling
|
68
|
|
- w = w + 1;
|
|
78
|
+ //for(int i = 2; i <= 32; i+=2){
|
|
79
|
+ //w++;
|
|
80
|
+ //}
|
|
81
|
+
|
|
82
|
+ System.out.println(w);
|
69
|
83
|
// each time through the loop
|
70
|
84
|
return w;
|
71
|
85
|
}
|
72
|
|
-
|
|
86
|
+
|
|
87
|
+ private int by2to32(){
|
|
88
|
+ int w = 0;
|
|
89
|
+ for(int i = 2; i <= 32; i+=2){
|
|
90
|
+ w++;
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ return w;
|
|
94
|
+ }
|
|
95
|
+
|
73
|
96
|
public int countDownFrom5000() {
|
74
|
97
|
int w = 0;
|
75
|
|
-
|
|
98
|
+ for(int i=1; i < 5001; i+=11){
|
|
99
|
+ w++;
|
|
100
|
+ }
|
76
|
101
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
77
|
102
|
// calling
|
78
|
|
- w = w + 1;
|
79
|
|
- // each time through the loop
|
80
|
103
|
|
|
104
|
+ // each time through the loop
|
|
105
|
+ System.out.println(w);
|
81
|
106
|
return w;
|
82
|
107
|
}
|
83
|
108
|
|
84
|
109
|
public int nestedFors() {
|
85
|
110
|
int w = 0;
|
86
|
|
-
|
|
111
|
+ for(int i = 0; i < 20; i++){
|
|
112
|
+ for(int j = 0; j <= 4; j++){
|
|
113
|
+ w++;
|
|
114
|
+ }
|
|
115
|
+ }
|
87
|
116
|
// Write a nested FOR loop(s), where one counts from
|
88
|
117
|
// 0 to less than 20 and the inner one counts from 0 to 4
|
89
|
118
|
// calling
|
90
|
|
- w = w + 1;
|
|
119
|
+
|
91
|
120
|
// each time through the inner loop
|
92
|
121
|
|
93
|
122
|
return w;
|
|
@@ -95,16 +124,26 @@ public class WriteLoops {
|
95
|
124
|
|
96
|
125
|
public int helloZipCode() {
|
97
|
126
|
int w = 0;
|
98
|
|
-
|
|
127
|
+ int counter = 0;
|
|
128
|
+ for(int i = 5; i < 105; i++){
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+ if(i > 51){
|
|
132
|
+ System.out.println("Hello Zipcode");
|
|
133
|
+ } else {
|
|
134
|
+ w++;
|
|
135
|
+ }
|
|
136
|
+ }
|
|
137
|
+
|
99
|
138
|
// Write a FOR loop that counts from 5 to 105. Put an IF
|
100
|
139
|
// statement inside the loop that checks the
|
101
|
140
|
// loop index counter and if it’s greater than 51,
|
102
|
141
|
// prints “Hello Zipcode” instead of the statement w = w + 1;
|
103
|
142
|
|
104
|
143
|
// calling
|
105
|
|
- w = w + 1;
|
|
144
|
+
|
106
|
145
|
// each time through the inner loop
|
107
|
|
-
|
|
146
|
+ System.out.println(w);
|
108
|
147
|
return w;
|
109
|
148
|
}
|
110
|
149
|
|
|
@@ -131,11 +170,14 @@ public class WriteLoops {
|
131
|
170
|
// After the loop is done, print “Honey, I’m Home!”
|
132
|
171
|
public int driveHome() {
|
133
|
172
|
int w = 0;
|
134
|
|
-
|
|
173
|
+ while(!gpsCurrentLocation().equals("Home")){
|
|
174
|
+ driveSomeMore();
|
|
175
|
+ w++;
|
|
176
|
+ }
|
135
|
177
|
// you need to use a .equals for two Strings.
|
136
|
|
-
|
|
178
|
+ System.out.println("Honey, I'm Home!");
|
137
|
179
|
// calling
|
138
|
|
- w = w + 1;
|
|
180
|
+
|
139
|
181
|
// each time through the inner loop
|
140
|
182
|
|
141
|
183
|
|
|
@@ -155,9 +197,16 @@ public class WriteLoops {
|
155
|
197
|
int runningScore = 0;
|
156
|
198
|
|
157
|
199
|
// do your while loop here
|
158
|
|
-
|
|
200
|
+ while(runningScore < highestScore){
|
|
201
|
+ if(runningScore < highestScore){
|
|
202
|
+ runningScore += currentScore;
|
|
203
|
+ currentScore = gameNextScore();
|
|
204
|
+ w++;
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ }
|
159
|
208
|
// calling
|
160
|
|
- w = w + 1;
|
|
209
|
+
|
161
|
210
|
// each time through the inner loop
|
162
|
211
|
|
163
|
212
|
return w; // >= 3;
|
|
@@ -172,12 +221,17 @@ public class WriteLoops {
|
172
|
221
|
int runningScore = 0;
|
173
|
222
|
|
174
|
223
|
// do your while loop here
|
175
|
|
-
|
|
224
|
+ do{
|
|
225
|
+ runningScore += currentScore;
|
|
226
|
+ currentScore = gameNextScore();
|
|
227
|
+ w++;
|
|
228
|
+ } while(runningScore < highestScore);
|
176
|
229
|
// calling
|
177
|
|
- w = w + 1;
|
|
230
|
+
|
|
231
|
+ System.out.println(w);
|
178
|
232
|
// each time through the inner loop
|
179
|
233
|
|
180
|
|
- return w >= 3;
|
|
234
|
+ return w <= 3;
|
181
|
235
|
}
|
182
|
236
|
|
183
|
237
|
// Write a WHILE loop that checks “serverIsRunning()” and if true
|
|
@@ -187,10 +241,19 @@ public class WriteLoops {
|
187
|
241
|
public int checkServerStatus() {
|
188
|
242
|
int w = 0;
|
189
|
243
|
String adminPhoneNumber = "+1 202 456 1111";
|
|
244
|
+ while(serverIsRunning()){
|
|
245
|
+ w++;
|
|
246
|
+ if(serverIsRunning() == true){
|
|
247
|
+ waitFor(5);
|
|
248
|
+ }else {
|
|
249
|
+ //sendEmergencyText("Help!", adminPhoneNumber());
|
|
250
|
+ //tryServerRestart();
|
|
251
|
+ }
|
|
252
|
+
|
|
253
|
+ }
|
190
|
254
|
|
191
|
|
-
|
192
|
255
|
// calling
|
193
|
|
- w = w + 1;
|
|
256
|
+
|
194
|
257
|
// each time through the inner loop
|
195
|
258
|
|
196
|
259
|
return w;
|
|
@@ -386,10 +449,10 @@ public class WriteLoops {
|
386
|
449
|
summer++;
|
387
|
450
|
return false;
|
388
|
451
|
}
|
389
|
|
- private void sendEmergencyText(String mesg, String phone) {
|
|
452
|
+ public void sendEmergencyText(String mesg, String phone) {
|
390
|
453
|
}
|
391
|
454
|
|
392
|
|
- private void tryServerRestart(String mesg, String phone) {
|
|
455
|
+ public void tryServerRestart(String mesg, String phone) {
|
393
|
456
|
}
|
394
|
457
|
|
395
|
458
|
int serverStatus = 5;
|