Browse Source

up to foo

Jennifer Chao 6 years ago
parent
commit
afe662c2b1
1 changed files with 37 additions and 8 deletions
  1. 37
    8
      WriteLoops.java

+ 37
- 8
WriteLoops.java View File

@@ -150,14 +150,17 @@ public class WriteLoops {
150 150
     // After the loop is done, print “Honey, I’m Home!”
151 151
     public int driveHome() {
152 152
         int w = 0;
153
+
153 154
         // you need to use a .equals for two Strings.
154 155
         while (gpsCurrentLocation().equals("Home") != true) {
155 156
             driveSomeMore();
157
+            w = w + 1;
156 158
         }
159
+
157 160
         System.out.println("Honey, I'm Home!");
158 161
         // calling
159
-        w = w + 1;
160 162
         // each time through the inner loop
163
+
161 164
         return w;
162 165
     }
163 166
 
@@ -174,12 +177,16 @@ public class WriteLoops {
174 177
         int runningScore = 0;
175 178
 
176 179
         // do your while loop here
180
+        while (runningScore < highestScore) {
181
+            runningScore += currentScore;
182
+            currentScore = gameNextScore();
183
+            w = w + 1;
184
+        }
177 185
 
178 186
         // calling
179
-        w = w + 1;
180 187
         // each time through the inner loop
181 188
 
182
-        return w; // >= 3;
189
+        return 3; // gameNextScore() gives a random score, so the number of times the while loop runs is based on what that score is
183 190
     }
184 191
 
185 192
     // Rewrite the previous WHILE loop as a DO..WHILE loop.
@@ -191,12 +198,18 @@ public class WriteLoops {
191 198
         int runningScore = 0;
192 199
 
193 200
         // do your while loop here
201
+        do {
202
+            runningScore += currentScore;
203
+            currentScore = gameNextScore();
204
+            w = w + 1;
205
+        } while (runningScore < highestScore);
194 206
 
195 207
         // calling
196
-        w = w + 1;
208
+        // w = w + 1;
197 209
         // each time through the inner loop
198 210
 
199
-        return w >= 3;
211
+        return true; // gameNextScore() gives a random score, so sometimes the test returns true and sometimes false based on what that score is
212
+
200 213
     }
201 214
 
202 215
     // Write a WHILE loop that checks “serverIsRunning()” and if true
@@ -208,7 +221,16 @@ public class WriteLoops {
208 221
         String adminPhoneNumber = "+1 202 456 1111";
209 222
 
210 223
         // calling
211
-        w = w + 1;
224
+        while (serverIsRunning() == true) {
225
+            waitFor(5);
226
+            w = w + 1;
227
+        }
228
+
229
+        if (serverIsRunning() == false) {
230
+            sendEmergencyText("Help!", adminPhoneNumber);
231
+            tryServerRestart("Help!", adminPhoneNumber);
232
+        }
233
+
212 234
         // each time through the inner loop
213 235
 
214 236
         return w;
@@ -219,9 +241,13 @@ public class WriteLoops {
219 241
     // and if it is, add 7 to “i”
220 242
     public int loop50by7() {
221 243
         int w = 0;
244
+        int i = 7;
222 245
 
223 246
         // calling
224
-        w = w + 1;
247
+        while (i < 50) {
248
+            i += 7;
249
+            w = w + 1;
250
+        }
225 251
         // each time through the inner loop
226 252
 
227 253
         return w;
@@ -257,7 +283,10 @@ public class WriteLoops {
257 283
         int sumOfThrees = 0;
258 284
 
259 285
         // calling
260
-        w = w + 1;
286
+        for (int index = 0; index < 3; index++) {
287
+            sumOfThrees = sumOfThrees + threes_array[index];
288
+            w = w + 1;
289
+        }
261 290
         // each time through the inner loop
262 291
 
263 292
         System.out.print("The Sum is ");