Kate Moore 6 years ago
parent
commit
16c6a4693e
3 changed files with 166 additions and 95 deletions
  1. 21
    5
      WriteIFs.java
  2. 132
    77
      WriteLoops.java
  3. 13
    13
      package.bluej

+ 21
- 5
WriteIFs.java View File

7
  */
7
  */
8
 public class WriteIFs
8
 public class WriteIFs
9
 {
9
 {
10
- 
10
+      int x = 0;
11
+      int tt_t = 0;
12
+      int tt_s = 1;
13
+      String ss = "";
14
+      int oo1 = 61;
15
+      int oo2 = 49;
16
+    
11
     public void playerDied(boolean player1) {
17
     public void playerDied(boolean player1) {
12
         // Write an IF statement that checks “player1.isAlive()” 
18
         // Write an IF statement that checks “player1.isAlive()” 
13
         // and if that’s false, calls “displayGameOver(player1)”
19
         // and if that’s false, calls “displayGameOver(player1)”
14
-     
20
+        if (isAlive(player1)== false) {
21
+            displayGameOver(player1);
22
+        }
15
     }
23
     }
16
     
24
     
17
     public String thermoSTAT(int room) {
25
     public String thermoSTAT(int room) {
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
-
29
+        if (tempurature(room) < 70) {
30
+            heatOn();
31
+        } else {
32
+            coolOn();
33
+        }
22
 
34
 
23
         
35
         
24
         return this.ss;
36
         return this.ss;
30
         // AND 
42
         // AND 
31
         // “insideTemp()” is less than 62, 
43
         // “insideTemp()” is less than 62, 
32
         // calls “startAFire(fireplace1)”
44
         // calls “startAFire(fireplace1)”
33
-
45
+        if (outsideTemp() < 50 || insideTemp() < 62 ) {
46
+            startAFire(fireplace1);
47
+        }
34
     }
48
     }
35
 
49
 
36
     public void checkFuel(double fuelLevel) {
50
     public void checkFuel(double fuelLevel) {
37
         // Write an IF statement that checks “fuelLevel” 
51
         // Write an IF statement that checks “fuelLevel” 
38
         // and if that check is less than 0.08, calls “refuel()”
52
         // and if that check is less than 0.08, calls “refuel()”
39
-
53
+        if ( fuelLevel < 0.08) {
54
+            refuel();
55
+        }
40
     }
56
     }
41
 
57
 
42
 
58
 

+ 132
- 77
WriteLoops.java View File

19
         int w = 0;
19
         int w = 0;
20
 
20
 
21
         // Write a FOR loop that counts from 1 to 10.
21
         // Write a FOR loop that counts from 1 to 10.
22
-            // calling
23
-            w = w + 1;
24
-            // each time through the loop
22
+        // calling
23
+        //w = w + 1;
24
+        // each time through the loop
25
 
25
 
26
         // this will tell the test how many times the loop executed.
26
         // this will tell the test how many times the loop executed.
27
+        for (int i = 1; i <= 5; i++) {
28
+            w = w + 1;
29
+        }
30
+
27
         return w;
31
         return w;
28
     }
32
     }
29
 
33
 
32
 
36
 
33
         // Write a FOR loop that counts from 1 to 10.
37
         // Write a FOR loop that counts from 1 to 10.
34
         // calling
38
         // calling
35
-        w = w + 1;
39
+        //w = w + 1;
36
         // each time through the loop
40
         // each time through the loop
37
-        
41
+        for (int i = 0; i<= 9; i++) {
42
+            w = w + 1;
43
+        }
44
+
38
         return w;
45
         return w;
39
     }
46
     }
40
 
47
 
43
 
50
 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
51
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
52
         // calling
46
-        w = w + 1;
53
+        //w = w + 1;
47
         // each time through the loop
54
         // each time through the loop
48
-        
55
+        for(int i = 21; i <= 31; i++) {
56
+            w = w + 1;
57
+        }
58
+
49
         return w;
59
         return w;
50
     }
60
     }
51
 
61
 
54
 
64
 
55
         // Write a FOR loop that counts down from 100 to 0.
65
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
66
         // calling
57
-        w = w + 1;
67
+        //w = w + 1;
58
         // each time through the loop
68
         // each time through the loop
59
-        
69
+        for(int i = 100; i > 0; i--) {
70
+            w = w + 1;
71
+        }
72
+
60
         return w;
73
         return w;
61
     }
74
     }
62
 
75
 
65
 
78
 
66
         // Write a FOR loop from 0 to 32 by 2s.
79
         // Write a FOR loop from 0 to 32 by 2s.
67
         // calling
80
         // calling
68
-        w = w + 1;
81
+        //w = w + 1;
69
         // each time through the loop
82
         // each time through the loop
83
+
84
+        for (int i = 32; i <= 0; i+=2) {
85
+            w = w + 1;
86
+        }
70
         return w;
87
         return w;
71
     }
88
     }
72
 
89
 
75
 
92
 
76
         // Write a FOR loop from 1 to less than 5001 by 11s.
93
         // Write a FOR loop from 1 to less than 5001 by 11s.
77
         // calling
94
         // calling
78
-        w = w + 1;
95
+        //w = w + 1;
79
         // each time through the loop
96
         // each time through the loop
80
-        
97
+
98
+        for(int i = 1; i <5001; i+=11) {
99
+            w = w + 1;
100
+        }
101
+
81
         return w;
102
         return w;
82
     }
103
     }
83
 
104
 
86
 
107
 
87
         // Write a nested FOR loop(s), where one counts from
108
         // 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
109
         // 0 to less than 20 and the inner one counts from 0 to 4
89
-                // calling
90
-                w = w + 1;
91
-                // each time through the inner loop
110
+        // calling
111
+        //w = w + 1;
112
+        // each time through the inner loop
113
+
114
+        for(w = 0; w < 100;) {
115
+            w = w + 1;
116
+            for(int j = w; j <= 4;) {
117
+                j+=j;
118
+            } 
119
+        }
92
 
120
 
93
         return w;
121
         return w;
94
     }
122
     }
101
         // loop index counter and if it’s greater than 51,
129
         // loop index counter and if it’s greater than 51,
102
         // prints “Hello Zipcode” instead of the statement w = w + 1;
130
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103
 
131
 
104
-                // calling
132
+        // calling
133
+        //w = w + 1;
134
+        // each time through the inner loop
135
+        for (int i = 5; i <=105; i++) {
136
+
137
+            if(i > 58) {
105
                 w = w + 1;
138
                 w = w + 1;
106
-            // each time through the inner loop
107
-        
139
+            }
140
+        }
141
+
108
         return w;
142
         return w;
109
     }
143
     }
110
 
144
 
133
         int w = 0;
167
         int w = 0;
134
 
168
 
135
         // you need to use a .equals for two Strings.
169
         // you need to use a .equals for two Strings.
170
+        while(gpsCurrentLocation().equals("Not Home")){
171
+            if(gpsCurrentLocation().equals("Not Home")){
172
+                driveSomeMore();
173
+                // calling
174
+                w += 1;
175
+                // each time through the inner loop
136
 
176
 
137
-            // calling
138
-            w = w + 1;
139
-            // each time through the inner loop
140
-        
141
-
142
-            return w;
177
+            }
178
+        }
179
+        System.out.println("Honey I'm Home");
180
+        return w;
143
     }
181
     }
144
 
182
 
145
     // Getting harder...
183
     // Getting harder...
149
     // "runningScore"
187
     // "runningScore"
150
     // and then sets “currentScore” to “gameNextScore()”
188
     // and then sets “currentScore” to “gameNextScore()”
151
     public int checkGameScore() {
189
     public int checkGameScore() {
152
-        int w = 0;
153
-        int highestScore = 236;
190
+        int w = 1;
191
+        int highestScore = 235;
154
         int currentScore = gameNextScore();
192
         int currentScore = gameNextScore();
155
         int runningScore = 0;
193
         int runningScore = 0;
156
 
194
 
157
-        // do your while loop here
158
- 
159
-            // calling
195
+        while (runningScore < highestScore){
196
+            runningScore += currentScore;
197
+            currentScore += gameNextScore();
198
+
160
             w = w + 1;
199
             w = w + 1;
161
-            // each time through the inner loop
162
-        
200
+
201
+        }
202
+        // do your while loop here
203
+
204
+        // calling
205
+        // w = w + 1;
206
+        // each time through the inner loop
207
+
163
         return w; // >= 3;
208
         return w; // >= 3;
164
-    }
165
 
209
 
210
+    }
166
     // Rewrite the previous WHILE loop as a DO..WHILE loop.
211
     // Rewrite the previous WHILE loop as a DO..WHILE loop.
167
     // Notice how the “runningScore” variable usage is different.
212
     // Notice how the “runningScore” variable usage is different.
168
     public boolean checkGameScoreDoWhile() {
213
     public boolean checkGameScoreDoWhile() {
169
         int w = 0;
214
         int w = 0;
170
-        int highestScore = 236;
215
+        int highestScore = 235;
171
         int currentScore = gameNextScore();
216
         int currentScore = gameNextScore();
172
         int runningScore = 0;
217
         int runningScore = 0;
218
+        boolean score;
219
+
220
+        do{ score=true;
221
+            runningScore += currentScore;
222
+            currentScore += gameNextScore();
223
+            w = w + 1;
224
+
225
+        }while(runningScore < runningScore);
173
 
226
 
174
         // do your while loop here
227
         // do your while loop here
175
 
228
 
176
-            // calling
177
-            w = w + 1;
178
-            // each time through the inner loop
229
+        // calling
230
+        // w = w + 1;
231
+        // each time through the inner loop
179
 
232
 
180
-        return w >= 3;
233
+        return score;
181
     }
234
     }
182
 
235
 
183
     // Write a WHILE loop that checks “serverIsRunning()” and if true
236
     // Write a WHILE loop that checks “serverIsRunning()” and if true
187
     public int checkServerStatus() {
240
     public int checkServerStatus() {
188
         int w = 0;
241
         int w = 0;
189
         String adminPhoneNumber = "+1 202 456 1111";
242
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
243
+        while (serverIsRunning()) {
244
+            if (serverIsRunning()==true) {
245
+                waitFor(5);      
246
+            } else {
247
+                sendEmergencyText("Help!",adminPhoneNumber);
248
+                tryServerRestart("","");
249
+            }
191
 
250
 
192
-        // calling
193
-        w = w + 1;
194
-        // each time through the inner loop
195
-        
251
+            // calling
252
+            w = w + 1;
253
+            // each time through the inner loop
254
+        }
196
         return w;
255
         return w;
197
     }
256
     }
198
 
257
 
202
     public int loop50by7() {
261
     public int loop50by7() {
203
         int w = 0;
262
         int w = 0;
204
 
263
 
264
+        // calling
265
+        w = w + 1;
266
+        // each time through the inner loop
205
 
267
 
206
-            // calling
207
-            w = w + 1;
208
-            // each time through the inner loop
209
-        
210
         return w;
268
         return w;
211
     }
269
     }
212
 
270
 
239
         int w = 0;
297
         int w = 0;
240
         int sumOfThrees = 0;
298
         int sumOfThrees = 0;
241
 
299
 
242
- 
243
-            // calling
244
-            w = w + 1;
245
-            // each time through the inner loop
246
-        
300
+        // calling
301
+        w = w + 1;
302
+        // each time through the inner loop
303
+
247
         System.out.print("The Sum is ");
304
         System.out.print("The Sum is ");
248
         System.out.println(sumOfThrees);
305
         System.out.println(sumOfThrees);
249
 
306
 
256
         int w = 0;
313
         int w = 0;
257
         int sumOfThrees = 0;
314
         int sumOfThrees = 0;
258
 
315
 
259
- 
260
-            // calling
261
-            w = w + 1;
262
-            // each time through the inner loop
263
-        
316
+        // calling
317
+        w = w + 1;
318
+        // each time through the inner loop
319
+
264
         System.out.print("The Sum is ");
320
         System.out.print("The Sum is ");
265
         System.out.println(sumOfThrees);
321
         System.out.println(sumOfThrees);
266
 
322
 
279
         boolean onTime = true;
335
         boolean onTime = true;
280
 
336
 
281
         // ADD YOUR CODE here.
337
         // ADD YOUR CODE here.
282
- 
283
-            // be sure to call
284
-            w = w + 1;
285
-            // each time inside the loop
286
-        
338
+
339
+        // be sure to call
340
+        w = w + 1;
341
+        // each time inside the loop
342
+
287
         return w;
343
         return w;
288
     }
344
     }
289
 
345
 
296
         int w = 0;
352
         int w = 0;
297
         int numberOfVotes = voteTallies.length;
353
         int numberOfVotes = voteTallies.length;
298
 
354
 
299
- 
300
-            // calling
301
-            w = w + 1;
302
-            // each time through the inner loop
303
-        
355
+        // calling
356
+        w = w + 1;
357
+        // each time through the inner loop
358
+
304
         return w;
359
         return w;
305
     }
360
     }
306
 
361
 
311
         int w = 0;
366
         int w = 0;
312
         int numberOfVotes = voteTallies.length;
367
         int numberOfVotes = voteTallies.length;
313
 
368
 
369
+        // calling
370
+        w = w + 1;
371
+        // each time through the inner loop
314
 
372
 
315
-            // calling
316
-            w = w + 1;
317
-            // each time through the inner loop
318
-        
319
         return w;
373
         return w;
320
     }
374
     }
321
 
375
 
378
     //         return (i >= 3);
432
     //         return (i >= 3);
379
     //     };
433
     //     };
380
     // };
434
     // };
381
-        private int summer = 0;
382
-        private boolean isSummer() {
383
-            if (summer == 3) {
384
-                return true;
385
-            }
386
-            summer++;
387
-            return false;
435
+    private int summer = 0;
436
+    private boolean isSummer() {
437
+        if (summer == 3) {
438
+            return true;
388
         }
439
         }
440
+        summer++;
441
+        return false;
442
+    }
443
+
389
     private void sendEmergencyText(String mesg, String phone) {
444
     private void sendEmergencyText(String mesg, String phone) {
390
     }
445
     }
391
 
446
 

+ 13
- 13
package.bluej View File

5
 dependency2.from=WriteIFsTest
5
 dependency2.from=WriteIFsTest
6
 dependency2.to=WriteIFs
6
 dependency2.to=WriteIFs
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
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
8
+editor.fx.0.height=716
9
+editor.fx.0.width=951
10
+editor.fx.0.x=329
11
+editor.fx.0.y=23
12
+objectbench.height=92
13
+objectbench.width=480
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.8490853658536586
16
+package.editor.height=550
17
+package.editor.width=378
18
+package.editor.x=0
19
+package.editor.y=23
20
+package.frame.height=714
21
+package.frame.width=504
22
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4
24
 package.showExtends=true
24
 package.showExtends=true