#40 FirstSaturday

Open
jtinkler wil 1 commits van jtinkler/FirstSaturday:master samenvoegen met master
3 gewijzigde bestanden met toevoegingen van 121 en 45 verwijderingen
  1. 25
    3
      WriteIFs.java
  2. 86
    32
      WriteLoops.java
  3. 10
    10
      package.bluej

+ 25
- 3
WriteIFs.java Bestand weergeven

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

+ 86
- 32
WriteLoops.java Bestand weergeven

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

+ 10
- 10
package.bluej Bestand weergeven

7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
 editor.fx.0.height=722
8
 editor.fx.0.height=722
9
 editor.fx.0.width=800
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
 objectbench.height=101
12
 objectbench.height=101
13
-objectbench.width=740
13
+objectbench.width=611
14
 package.divider.horizontal=0.6
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
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4
24
 package.showExtends=true
24
 package.showExtends=true