#40 FirstSaturday

Открыто
jtinkler хочет смерджить 1 коммит(ов) из jtinkler/FirstSaturday:master в master
3 измененных файлов: 121 добавлений и 45 удалений
  1. 25
    3
      WriteIFs.java
  2. 86
    32
      WriteLoops.java
  3. 10
    10
      package.bluej

+ 25
- 3
WriteIFs.java Просмотреть файл

@@ -11,6 +11,14 @@ public class WriteIFs
11 11
     public void playerDied(boolean player1) {
12 12
         // Write an IF statement that checks “player1.isAlive()” 
13 13
         // and if that’s false, calls “displayGameOver(player1)”
14
+       
15
+            if (player1 == true) {
16
+                displayGameOver(player1);
17
+        }
18
+     
19
+            
20
+           
21
+            
14 22
      
15 23
     }
16 24
     
@@ -18,8 +26,12 @@ public class WriteIFs
18 26
         // Write an IF statement that checks the 
19 27
         // “temperature(room)” and if that check is less than 70, 
20 28
         // calls “heatOn()” else calls “coolOn()”
21
-
22
-
29
+        
30
+            if (tempurature (room) < 70) {
31
+                heatOn();
32
+            } else {
33
+                    coolOn();
34
+            }
23 35
         
24 36
         return this.ss;
25 37
     }
@@ -30,12 +42,22 @@ public class WriteIFs
30 42
         // AND 
31 43
         // “insideTemp()” is less than 62, 
32 44
         // calls “startAFire(fireplace1)”
45
+        
46
+        if (outsideTemp() < 50 || insideTemp() < 62) {
47
+          
48
+            startAFire(fireplace1);
49
+        }
50
+        
33 51
 
34 52
     }
35 53
 
36 54
     public void checkFuel(double fuelLevel) {
37 55
         // Write an IF statement that checks “fuelLevel” 
38 56
         // and if that check is less than 0.08, calls “refuel()”
57
+        
58
+        if (fuelLevel < 0.08) {
59
+            refuel();
60
+        }
39 61
 
40 62
     }
41 63
 
@@ -46,7 +68,7 @@ public class WriteIFs
46 68
      * 
47 69
      * 
48 70
      * instance variables
49
-     * / 
71
+     */ 
50 72
    int x;
51 73
    int tt_t;
52 74
    int tt_s;

+ 86
- 32
WriteLoops.java Просмотреть файл

@@ -18,10 +18,9 @@ public class WriteLoops {
18 18
     public int oneToFive() {
19 19
         int w = 0;
20 20
 
21
-        // Write a FOR loop that counts from 1 to 10.
22
-            // calling
23
-            w = w + 1;
24
-            // each time through the loop
21
+       for (int i =1; i <=5; i++){
22
+         w = w + 1;
23
+        } // each time through the loop
25 24
 
26 25
         // this will tell the test how many times the loop executed.
27 26
         return w;
@@ -30,17 +29,17 @@ public class WriteLoops {
30 29
     public int oneToTen() {
31 30
         int w = 0;
32 31
 
33
-        // Write a FOR loop that counts from 1 to 10.
32
+        for (int i = 1; i <= 10; i++) {// Write a FOR loop that counts from 1 to 10.
34 33
         // calling
35 34
         w = w + 1;
36
-        // each time through the loop
35
+    }// each time through the loop
37 36
         
38 37
         return w;
39 38
     }
40 39
 
41 40
     public int startAtTwentyOne() {
42 41
         int w = 0;
43
-
42
+        for (int i = 21; i <= 31; i++)
44 43
         // Write a FOR loop that makes 10 iterations, start at 21.
45 44
         // calling
46 45
         w = w + 1;
@@ -51,7 +50,7 @@ public class WriteLoops {
51 50
 
52 51
     public int countDown() {
53 52
         int w = 0;
54
-
53
+        for (int i = 100; i > 0; i--)
55 54
         // Write a FOR loop that counts down from 100 to 0.
56 55
         // calling
57 56
         w = w + 1;
@@ -61,18 +60,19 @@ public class WriteLoops {
61 60
     }
62 61
 
63 62
     public int byTwoTo32() {
64
-        int w = 0;
65
-
63
+        int w = 34;
64
+        for (int i = 0; i <= 32; i+=2){
66 65
         // Write a FOR loop from 0 to 32 by 2s.
67 66
         // calling
68 67
         w = w + 1;
68
+    }
69 69
         // each time through the loop
70 70
         return w;
71 71
     }
72 72
 
73 73
     public int countDownFrom5000() {
74 74
         int w = 0;
75
-
75
+        for (int i = 1; i < 5001; i+= 11)
76 76
         // Write a FOR loop from 1 to less than 5001 by 11s.
77 77
         // calling
78 78
         w = w + 1;
@@ -83,19 +83,31 @@ public class WriteLoops {
83 83
 
84 84
     public int nestedFors() {
85 85
         int w = 0;
86
+        
87
+        for (int i= 0; i < 20; i++){
88
+         for (int j = 0; j <= 4; j++){
86 89
 
87
-        // Write a nested FOR loop(s), where one counts from
90
+        //Write a nested FOR loop(s), where one counts from
88 91
         // 0 to less than 20 and the inner one counts from 0 to 4
89 92
                 // calling
90 93
                 w = w + 1;
91
-                // each time through the inner loop
92
-
94
+            }     // each time through the inner loop
95
+        }
93 96
         return w;
94 97
     }
95 98
 
96 99
     public int helloZipCode() {
97 100
         int w = 0;
98
-
101
+        
102
+        for (int i=5; i <= 105; i++){
103
+            if (i >= 51){
104
+                System.out.println("Hello Zipcode");
105
+            }
106
+           else  w = w + 1;
107
+        }
108
+        
109
+        
110
+        
99 111
         // Write a FOR loop that counts from 5 to 105. Put an IF
100 112
         // statement inside the loop that checks the
101 113
         // loop index counter and if it’s greater than 51,
@@ -131,11 +143,18 @@ public class WriteLoops {
131 143
     // After the loop is done, print “Honey, I’m Home!”
132 144
     public int driveHome() {
133 145
         int w = 0;
134
-
146
+        
147
+        while (!gpsCurrentLocation().equals("Home")) {
148
+            
149
+            driveSomeMore();
150
+            
151
+            w = w +1;
152
+        }
153
+            System.out.println("Honey I am Home.");
135 154
         // you need to use a .equals for two Strings.
136 155
 
137 156
             // calling
138
-            w = w + 1;
157
+        
139 158
             // each time through the inner loop
140 159
         
141 160
 
@@ -155,12 +174,18 @@ public class WriteLoops {
155 174
         int runningScore = 0;
156 175
 
157 176
         // do your while loop here
177
+        while ( runningScore < highestScore ) {
178
+                
179
+                w = w + 1;
180
+                runningScore += currentScore;
181
+        
182
+        }
158 183
  
159 184
             // calling
160
-            w = w + 1;
185
+          
161 186
             // each time through the inner loop
162 187
         
163
-        return w; // >= 3;
188
+        return w ;
164 189
     }
165 190
 
166 191
     // Rewrite the previous WHILE loop as a DO..WHILE loop.
@@ -172,9 +197,14 @@ public class WriteLoops {
172 197
         int runningScore = 0;
173 198
 
174 199
         // do your while loop here
175
-
200
+            do {
201
+                w = w + 1;
202
+                
203
+             runningScore += currentScore;
204
+             
205
+            } while (runningScore < highestScore);
176 206
             // calling
177
-            w = w + 1;
207
+           
178 208
             // each time through the inner loop
179 209
 
180 210
         return w >= 3;
@@ -188,9 +218,17 @@ public class WriteLoops {
188 218
         int w = 0;
189 219
         String adminPhoneNumber = "+1 202 456 1111";
190 220
         
221
+        while (serverIsRunning() == true) {
222
+            waitFor(5);
223
+            w = w + 1;
224
+        if (serverIsRunning() == false) {
225
+        sendEmergencyText("Help!" , adminPhoneNumber);
226
+            
227
+            tryServerRestart("Help!", adminPhoneNumber);
228
+        }
191 229
 
192 230
         // calling
193
-        w = w + 1;
231
+    }
194 232
         // each time through the inner loop
195 233
         
196 234
         return w;
@@ -201,28 +239,37 @@ public class WriteLoops {
201 239
     // and if it is, add 7 to “i”
202 240
     public int loop50by7() {
203 241
         int w = 0;
204
-
205
-
206
-            // calling
207
-            w = w + 1;
242
+        int i = 7;
243
+        
244
+        while ( i < 50) {
245
+        
246
+                i = i + 7;
247
+                // calling
248
+                w = w + 1;
249
+            }       
208 250
             // each time through the inner loop
251
+         
252
+    
253
+        return i;
209 254
         
210
-        return w;
211 255
     }
212 256
 
213
-    int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
257
+    public int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
214 258
 
215 259
     // Foo is method that add the first 7 factors of three together and prints
216 260
     // out the sum of them all.
217 261
     public int foo() {
218
-        int w = 0;
262
+       int w = 0;
219 263
         // this is an array of ints. it is of length 7 (from 0 -> 6)
220 264
         int sumOfThrees = 0;
221 265
 
222 266
         // this is a so called Enhanced for loop
223 267
         for (int index : threes_array) {
224 268
             sumOfThrees = sumOfThrees + threes_array[index];
225
-            // calling
269
+            
270
+            for (int i = 0; i < threes_array.length; i++){
271
+            
272
+            }            // calling
226 273
             w = w + 1;
227 274
             // each time through the inner loop
228 275
         }
@@ -238,6 +285,8 @@ public class WriteLoops {
238 285
     public int rewriteFooAsFor() {
239 286
         int w = 0;
240 287
         int sumOfThrees = 0;
288
+        
289
+        
241 290
 
242 291
  
243 292
             // calling
@@ -277,13 +326,18 @@ public class WriteLoops {
277 326
     public int manageYardAndJunior() {
278 327
         int w = 0;
279 328
         boolean onTime = true;
329
+        boolean yardNeedsMowed = true;
280 330
 
281 331
         // ADD YOUR CODE here.
282
- 
332
+        while(isSummer() == true) {
333
+            if(yardNeedsMowed == true) {
334
+                yellAtJuniorToMowLawn();
335
+            }
336
+        }
283 337
             // be sure to call
284 338
             w = w + 1;
285 339
             // each time inside the loop
286
-        
340
+        sendJuniorBackToSchool("so boring");
287 341
         return w;
288 342
     }
289 343
 

+ 10
- 10
package.bluej Просмотреть файл

@@ -7,18 +7,18 @@ dependency2.to=WriteIFs
7 7
 dependency2.type=UsesDependency
8 8
 editor.fx.0.height=722
9 9
 editor.fx.0.width=800
10
-editor.fx.0.x=560
11
-editor.fx.0.y=118
10
+editor.fx.0.x=159
11
+editor.fx.0.y=46
12 12
 objectbench.height=101
13
-objectbench.width=740
13
+objectbench.width=611
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.755656108597285
16
+package.editor.height=327
17
+package.editor.width=493
18
+package.editor.x=410
19
+package.editor.y=197
20
+package.frame.height=500
21
+package.frame.width=635
22 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true