Jose Bedolla 6 years ago
parent
commit
c786b15e08
2 changed files with 104 additions and 35 deletions
  1. 92
    23
      WriteLoops.java
  2. 12
    12
      package.bluej

+ 92
- 23
WriteLoops.java View File

@@ -75,14 +75,15 @@ public class WriteLoops {
75 75
 
76 76
     public int byTwoTo32() {
77 77
         int w = 0;
78
-
78
+        
79 79
         // Write a FOR loop from 0 to 32 by 2s.
80 80
         // calling
81
-        for(int i = 1; i <= 32; i+=2)
81
+        for(int i = 32; i <= 0; i++)
82 82
         {
83 83
             w = w + 1;
84 84
         }
85 85
         // each time through the loop
86
+
86 87
         return w;
87 88
     }
88 89
 
@@ -91,7 +92,10 @@ public class WriteLoops {
91 92
 
92 93
         // Write a FOR loop from 1 to less than 5001 by 11s.
93 94
         // calling
94
-        w = w + 1;
95
+        for(int i =1; i < 5001; i+=11)
96
+        {
97
+            w = w + 1;
98
+        }
95 99
         // each time through the loop
96 100
         
97 101
         return w;
@@ -103,7 +107,13 @@ public class WriteLoops {
103 107
         // Write a nested FOR loop(s), where one counts from
104 108
         // 0 to less than 20 and the inner one counts from 0 to 4
105 109
                 // calling
106
-                w = w + 1;
110
+                for(int i =0;i<20;i++)
111
+                {
112
+                    for(int j=0;j<=4;j++)
113
+                    {
114
+                        w = w +1;
115
+                    }
116
+                }
107 117
                 // each time through the inner loop
108 118
 
109 119
         return w;
@@ -116,9 +126,18 @@ public class WriteLoops {
116 126
         // statement inside the loop that checks the
117 127
         // loop index counter and if it’s greater than 51,
118 128
         // prints “Hello Zipcode” instead of the statement w = w + 1;
119
-
129
+        for(int i =5;i<=105;i++)
130
+        {
131
+            if(i>51)
132
+            {
133
+             System.out.println("Hello Zipcode");
134
+            }
135
+            else
136
+            {
137
+                w = w+1;
138
+            }
139
+        }
120 140
                 // calling
121
-                w = w + 1;
122 141
             // each time through the inner loop
123 142
         
124 143
         return w;
@@ -151,8 +170,13 @@ public class WriteLoops {
151 170
         // you need to use a .equals for two Strings.
152 171
 
153 172
             // calling
154
-            w = w + 1;
173
+            while(gpsCurrentLocation()!="Home")
174
+            {
175
+                driveSomeMore();
176
+                w = w +1;
177
+            }
155 178
             // each time through the inner loop
179
+            System.out.println("Honey, I'm Home!");
156 180
         
157 181
 
158 182
             return w;
@@ -172,8 +196,17 @@ public class WriteLoops {
172 196
 
173 197
         // do your while loop here
174 198
  
175
-            // calling
176
-            w = w + 1;
199
+            while(runningScore < highestScore)
200
+            {
201
+                if(runningScore < highestScore)
202
+                {
203
+                    runningScore = runningScore + currentScore;
204
+                    
205
+                }
206
+                w = w + 1;
207
+            }
208
+            currentScore = gameNextScore();
209
+            
177 210
             // each time through the inner loop
178 211
         
179 212
         return w; // >= 3;
@@ -187,11 +220,14 @@ public class WriteLoops {
187 220
         int currentScore = gameNextScore();
188 221
         int runningScore = 0;
189 222
 
190
-        // do your while loop here
223
+                do{
224
+                    if(runningScore < highestScore)
225
+                {
226
+                    runningScore = runningScore + currentScore;
227
+                    w = w + 1;
228
+                }
229
+            } while(runningScore < highestScore);
191 230
 
192
-            // calling
193
-            w = w + 1;
194
-            // each time through the inner loop
195 231
 
196 232
         return w >= 3;
197 233
     }
@@ -203,10 +239,20 @@ public class WriteLoops {
203 239
     public int checkServerStatus() {
204 240
         int w = 0;
205 241
         String adminPhoneNumber = "+1 202 456 1111";
206
-        
242
+        while(serverIsRunning()==true)
243
+        {
244
+            waitFor(5);
245
+              w = w + 1;
246
+        }
247
+        if(serverIsRunning()==false)
248
+        {
249
+            sendEmergencyText("Help!", adminPhoneNumber);
250
+            tryServerRestart("Help!", adminPhoneNumber);
251
+        }
207 252
 
253
+        
208 254
         // calling
209
-        w = w + 1;
255
+      
210 256
         // each time through the inner loop
211 257
         
212 258
         return w;
@@ -217,6 +263,13 @@ public class WriteLoops {
217 263
     // and if it is, add 7 to “i”
218 264
     public int loop50by7() {
219 265
         int w = 0;
266
+        int i = 7;
267
+        
268
+        while(i < 50)
269
+        {
270
+         i = i + 7;
271
+         
272
+        }
220 273
 
221 274
 
222 275
             // calling
@@ -254,11 +307,12 @@ public class WriteLoops {
254 307
     public int rewriteFooAsFor() {
255 308
         int w = 0;
256 309
         int sumOfThrees = 0;
257
-
258
- 
310
+        for (int i=0; i<threes_array.length; i++) {
311
+            sumOfThrees = sumOfThrees + threes_array[i];
259 312
             // calling
260 313
             w = w + 1;
261 314
             // each time through the inner loop
315
+        }
262 316
         
263 317
         System.out.print("The Sum is ");
264 318
         System.out.println(sumOfThrees);
@@ -271,11 +325,13 @@ public class WriteLoops {
271 325
     public int rewriteFooAsWhile() {
272 326
         int w = 0;
273 327
         int sumOfThrees = 0;
274
-
275
- 
328
+        int i = 0;
329
+        while(i<threes_array.length) {
330
+            sumOfThrees = sumOfThrees + threes_array[i];
276 331
             // calling
277 332
             w = w + 1;
278 333
             // each time through the inner loop
334
+        }
279 335
         
280 336
         System.out.print("The Sum is ");
281 337
         System.out.println(sumOfThrees);
@@ -293,11 +349,20 @@ public class WriteLoops {
293 349
     public int manageYardAndJunior() {
294 350
         int w = 0;
295 351
         boolean onTime = true;
352
+        boolean yardNeedsMowed = true;
296 353
 
297
-        // ADD YOUR CODE here.
354
+        while(isSummer())
355
+        {
356
+            if(yardNeedsMowed=true)
357
+            {
358
+                yellAtJuniorToMowLawn();
359
+            }
360
+             w = w + 1;
361
+        }
362
+            sendJuniorBackToSchool("junior back to school");
298 363
  
299 364
             // be sure to call
300
-            w = w + 1;
365
+           
301 366
             // each time inside the loop
302 367
         
303 368
         return w;
@@ -312,9 +377,13 @@ public class WriteLoops {
312 377
         int w = 0;
313 378
         int numberOfVotes = voteTallies.length;
314 379
 
315
- 
380
+        for(int i=0; i<voteTallies.length; i++)
381
+        {
382
+            System.out.println(i);
383
+             w = w + 1;
384
+        }
316 385
             // calling
317
-            w = w + 1;
386
+
318 387
             // each time through the inner loop
319 388
         
320 389
         return w;

+ 12
- 12
package.bluej View File

@@ -5,20 +5,20 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=WriteIFsTest
6 6
 dependency2.to=WriteIFs
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
8
+editor.fx.0.height=714
9 9
 editor.fx.0.width=800
10
-editor.fx.0.x=560
11
-editor.fx.0.y=118
12
-objectbench.height=101
13
-objectbench.width=740
10
+editor.fx.0.x=474
11
+editor.fx.0.y=23
12
+objectbench.height=92
13
+objectbench.width=523
14 14
 package.divider.horizontal=0.6
15
-package.divider.vertical=0.8625954198473282
16
-package.editor.height=671
17
-package.editor.width=1139
18
-package.editor.x=112
19
-package.editor.y=89
20
-package.frame.height=844
21
-package.frame.width=1265
15
+package.divider.vertical=0.831918505942275
16
+package.editor.height=483
17
+package.editor.width=405
18
+package.editor.x=1
19
+package.editor.y=34
20
+package.frame.height=647
21
+package.frame.width=547
22 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true