|
@@ -14,7 +14,9 @@ import java.util.function.Supplier;
|
14
|
14
|
public class WriteLoops {
|
15
|
15
|
|
16
|
16
|
private static final int _3 = 3;
|
17
|
|
-
|
|
17
|
+ int serverStatus;
|
|
18
|
+ private int gps;
|
|
19
|
+
|
18
|
20
|
public int oneToFive() {
|
19
|
21
|
int w=0;
|
20
|
22
|
// Write a FOR loop that counts from 1 to 10.
|
|
@@ -75,9 +77,10 @@ public class WriteLoops {
|
75
|
77
|
|
76
|
78
|
// Write a FOR loop from 0 to 32 by 2s.
|
77
|
79
|
// calling
|
78
|
|
- for(int i=0;i<=32;i=+2)
|
|
80
|
+ for(int i=0;i<32;i=i+2)
|
79
|
81
|
{
|
80
|
|
- w = w + 1;
|
|
82
|
+ System.out.println ("byTwoto32 i = " + i);
|
|
83
|
+ w++;
|
81
|
84
|
}// each time through the loop
|
82
|
85
|
return w;
|
83
|
86
|
}
|
|
@@ -87,7 +90,7 @@ public class WriteLoops {
|
87
|
90
|
|
88
|
91
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
89
|
92
|
// calling
|
90
|
|
- for(int i=1;i<5001;i=+11)
|
|
93
|
+ for(int i=1;i<5001;i=i+11)
|
91
|
94
|
w = w + 1;
|
92
|
95
|
// each time through the loop
|
93
|
96
|
|
|
@@ -155,10 +158,11 @@ public class WriteLoops {
|
155
|
158
|
// After the loop is done, print “Honey, I’m Home!”
|
156
|
159
|
public int driveHome() {
|
157
|
160
|
int w = 0;
|
158
|
|
- String current=gpsCurrentLocation();
|
159
|
|
- while(!current.equals("home"))
|
|
161
|
+
|
|
162
|
+ while(!gpsCurrentLocation().equals("Home"))
|
160
|
163
|
{
|
161
|
164
|
this.driveSomeMore();
|
|
165
|
+ w=w+1;
|
162
|
166
|
}
|
163
|
167
|
System.out.println ("Honey, I'm Home!");
|
164
|
168
|
|
|
@@ -223,16 +227,17 @@ public class WriteLoops {
|
223
|
227
|
public int checkServerStatus() {
|
224
|
228
|
int w = 0;
|
225
|
229
|
String adminPhoneNumber = "+1 202 456 1111";
|
226
|
|
- boolean result=serverIsRunning();
|
227
|
|
- while(result == true)
|
|
230
|
+
|
|
231
|
+ while(this.serverIsRunning())
|
228
|
232
|
{
|
229
|
233
|
waitFor(5);
|
|
234
|
+ w=w+1;
|
230
|
235
|
}
|
231
|
|
- if(result==false)
|
|
236
|
+ if(!this.serverIsRunning())
|
232
|
237
|
{
|
233
|
|
- sendEmergencyText("Help","adminPhoneNumber");
|
234
|
|
- tryServerRestart("","");
|
235
|
|
- w=w+1;
|
|
238
|
+ sendEmergencyText("Help",adminPhoneNumber);
|
|
239
|
+ tryServerRestart("Help", adminPhoneNumber);
|
|
240
|
+
|
236
|
241
|
}
|
237
|
242
|
// calling
|
238
|
243
|
|
|
@@ -252,10 +257,7 @@ public class WriteLoops {
|
252
|
257
|
w = w + 1;
|
253
|
258
|
}
|
254
|
259
|
|
255
|
|
- // calling
|
256
|
260
|
|
257
|
|
- // each time through the inner loop
|
258
|
|
-
|
259
|
261
|
return w;
|
260
|
262
|
}
|
261
|
263
|
|
|
@@ -283,7 +285,7 @@ public class WriteLoops {
|
283
|
285
|
return w;
|
284
|
286
|
}
|
285
|
287
|
|
286
|
|
- // Ponder this: can all FOR loops be rewritten as WHILE loops?
|
|
288
|
+ // Ponder this: can all FOR loops be rewritten as WHILE loops? yes
|
287
|
289
|
// rewrite the loop inside of "foo()" as a standard for loop
|
288
|
290
|
// with 'i' as its index variable.
|
289
|
291
|
public int rewriteFooAsFor() {
|
|
@@ -336,15 +338,16 @@ public class WriteLoops {
|
336
|
338
|
int w = 0;
|
337
|
339
|
boolean onTime = true;
|
338
|
340
|
boolean yardNeedsMowed=true;
|
339
|
|
- while(isSummer())
|
|
341
|
+ while(!isSummer())
|
340
|
342
|
{
|
|
343
|
+ w = w + 1;
|
341
|
344
|
if(yardNeedsMowed==true)
|
342
|
345
|
{
|
343
|
346
|
yellAtJuniorToMowLawn();
|
344
|
|
- w = w + 1;
|
|
347
|
+
|
345
|
348
|
}else
|
346
|
349
|
{
|
347
|
|
- sendJuniorBackToSchool("");
|
|
350
|
+ sendJuniorBackToSchool("First Day of School");
|
348
|
351
|
}
|
349
|
352
|
}
|
350
|
353
|
|
|
@@ -422,9 +425,11 @@ public class WriteLoops {
|
422
|
425
|
public WriteLoops() {
|
423
|
426
|
// initialise instance variables
|
424
|
427
|
x = 0;
|
|
428
|
+ gps = 0;
|
|
429
|
+ serverStatus = 5;
|
425
|
430
|
}
|
426
|
431
|
|
427
|
|
- private int gps = 0;
|
|
432
|
+
|
428
|
433
|
|
429
|
434
|
private String gpsCurrentLocation() {
|
430
|
435
|
if (this.gps > 5) {
|
|
@@ -474,14 +479,17 @@ public class WriteLoops {
|
474
|
479
|
private void tryServerRestart(String mesg, String phone) {
|
475
|
480
|
}
|
476
|
481
|
|
477
|
|
- int serverStatus = 5;
|
|
482
|
+
|
478
|
483
|
|
479
|
484
|
private boolean serverIsRunning() {
|
480
|
|
- return (serverStatus < 20);
|
|
485
|
+ //System.out.println ("ServerIsRunning - serverStatus - " + serverStatus );
|
|
486
|
+ return (this.serverStatus < 20);
|
481
|
487
|
}
|
482
|
488
|
|
483
|
489
|
private void waitFor(int interval) {
|
484
|
|
- serverStatus += interval;
|
|
490
|
+ //System.out.println ("waitfor before serverStatus - " + this.serverStatus);
|
|
491
|
+ this.serverStatus += interval;
|
|
492
|
+ //System.out.println ("waitfor after serverStatus - " + this.serverStatus);
|
485
|
493
|
}
|
486
|
494
|
|
487
|
495
|
}
|