Akeem Cherry преди 6 години
родител
ревизия
78dd27484c
променени са 3 файла, в които са добавени 172 реда и са изтрити 92 реда
  1. 17
    1
      WriteIFs.java
  2. 129
    65
      WriteLoops.java
  3. 26
    26
      package.bluej

+ 17
- 1
WriteIFs.java Целия файл

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

+ 129
- 65
WriteLoops.java Целия файл

@@ -19,9 +19,12 @@ public class WriteLoops {
19 19
         int w = 0;
20 20
 
21 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
+        for(int i=1;i<=5;i++){
26
+            w +=1;   
27
+        }
25 28
 
26 29
         // this will tell the test how many times the loop executed.
27 30
         return w;
@@ -32,9 +35,12 @@ public class WriteLoops {
32 35
 
33 36
         // Write a FOR loop that counts from 1 to 10.
34 37
         // calling
35
-        w = w + 1;
38
+        //w = w + 1;
36 39
         // each time through the loop
37
-        
40
+        for(int i=1;i<=10;i++){
41
+            w +=1;
42
+        }
43
+
38 44
         return w;
39 45
     }
40 46
 
@@ -45,7 +51,10 @@ public class WriteLoops {
45 51
         // calling
46 52
         w = w + 1;
47 53
         // each time through the loop
48
-        
54
+        for(int i=21;i<=30;i++){
55
+            w +=1;
56
+        }
57
+
49 58
         return w;
50 59
     }
51 60
 
@@ -56,7 +65,10 @@ public class WriteLoops {
56 65
         // calling
57 66
         w = w + 1;
58 67
         // each time through the loop
59
-        
68
+        for(int i=99;i>=1;i--){
69
+            w +=1;
70
+        }
71
+
60 72
         return w;
61 73
     }
62 74
 
@@ -65,8 +77,11 @@ public class WriteLoops {
65 77
 
66 78
         // Write a FOR loop from 0 to 32 by 2s.
67 79
         // calling
68
-        w = w + 1;
80
+        //w = w + 1;
69 81
         // each time through the loop
82
+        for (int i=1;i<=32;i+=2){
83
+            w +=0;
84
+        }
70 85
         return w;
71 86
     }
72 87
 
@@ -75,9 +90,13 @@ public class WriteLoops {
75 90
 
76 91
         // Write a FOR loop from 1 to less than 5001 by 11s.
77 92
         // calling
78
-        w = w + 1;
93
+        //w = w + 1;
79 94
         // each time through the loop
80
-        
95
+        int i = 0;
96
+        for(i=1;i<5000;i+=11){
97
+            w +=1;
98
+        }
99
+
81 100
         return w;
82 101
     }
83 102
 
@@ -86,10 +105,18 @@ public class WriteLoops {
86 105
 
87 106
         // Write a nested FOR loop(s), where one counts from
88 107
         // 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
108
+        // calling
109
+        //w = w + 1;
110
+        // each time through the inner loop
111
+        int i =0;
112
+        for(i=0;i<20;i++){
113
+            int j = 0;
114
+            for(j=0;j<=4;j++){
115
+                w +=1;
116
+
117
+            }
92 118
 
119
+        }
93 120
         return w;
94 121
     }
95 122
 
@@ -101,10 +128,20 @@ public class WriteLoops {
101 128
         // loop index counter and if it’s greater than 51,
102 129
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103 130
 
104
-                // calling
105
-                w = w + 1;
106
-            // each time through the inner loop
107
-        
131
+        // calling
132
+        //w = w + 1;
133
+        // each time through the inner loop
134
+        int i = 0;
135
+        for (i=5;i<=105;i++){
136
+            System.out.println(w);
137
+            if (i>51){
138
+                System.out.println("Hello Zipcode");
139
+            }
140
+            else{
141
+                w +=1;
142
+            }
143
+        }
144
+
108 145
         return w;
109 146
     }
110 147
 
@@ -134,12 +171,16 @@ public class WriteLoops {
134 171
 
135 172
         // you need to use a .equals for two Strings.
136 173
 
137
-            // calling
174
+        // calling
175
+        //w = w + 1;
176
+        // each time through the inner loop
177
+        while(!gpsCurrentLocation().equals("Home")){
138 178
             w = w + 1;
139
-            // each time through the inner loop
140
-        
179
+            driveSomeMore();
180
+        }
181
+        System.out.println("Honey, I'm home");
141 182
 
142
-            return w;
183
+        return w;
143 184
     }
144 185
 
145 186
     // Getting harder...
@@ -155,11 +196,15 @@ public class WriteLoops {
155 196
         int runningScore = 0;
156 197
 
157 198
         // do your while loop here
158
- 
159
-            // calling
160
-            w = w + 1;
199
+
200
+        // calling
201
+        while (runningScore < highestScore){
202
+            w += 1;
203
+            runningScore += currentScore;
204
+            currentScore = gameNextScore();
161 205
             // each time through the inner loop
162
-        
206
+        }
207
+
163 208
         return w; // >= 3;
164 209
     }
165 210
 
@@ -173,9 +218,14 @@ public class WriteLoops {
173 218
 
174 219
         // do your while loop here
175 220
 
176
-            // calling
221
+        // calling
222
+        do{
177 223
             w = w + 1;
178
-            // each time through the inner loop
224
+            runningScore += currentScore;
225
+            currentScore = gameNextScore();
226
+        }
227
+        while (runningScore < highestScore);
228
+        // each time through the inner loop
179 229
 
180 230
         return w >= 3;
181 231
     }
@@ -187,12 +237,19 @@ public class WriteLoops {
187 237
     public int checkServerStatus() {
188 238
         int w = 0;
189 239
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
191 240
 
192 241
         // calling
193
-        w = w + 1;
242
+        //w = w + 1;
194 243
         // each time through the inner loop
195
-        
244
+        while (serverIsRunning()) {
245
+            waitFor(5);
246
+            w +=1;
247
+        }
248
+        if (!serverIsRunning()){
249
+            sendEmergencyText("Help!", adminPhoneNumber);
250
+            //tryServerRestart();
251
+        }
252
+
196 253
         return w;
197 254
     }
198 255
 
@@ -201,12 +258,16 @@ public class WriteLoops {
201 258
     // and if it is, add 7 to “i”
202 259
     public int loop50by7() {
203 260
         int w = 0;
261
+        int i = 7;
204 262
 
263
+        // calling
264
+        //w = w + 1;
265
+        // each time through the inner loop
266
+        while (i < 50){
267
+            i +=7;
268
+            w +=1;
269
+        }
205 270
 
206
-            // calling
207
-            w = w + 1;
208
-            // each time through the inner loop
209
-        
210 271
         return w;
211 272
     }
212 273
 
@@ -238,12 +299,17 @@ public class WriteLoops {
238 299
     public int rewriteFooAsFor() {
239 300
         int w = 0;
240 301
         int sumOfThrees = 0;
302
+        int i = 0;
303
+
304
+        // calling
305
+        w = w + 1;
306
+        // each time through the inner loop
307
+        while (i < threes_array.length){
308
+            sumOfThrees = threes_array[i];
309
+            i++;
310
+            w +=1;
311
+        }
241 312
 
242
- 
243
-            // calling
244
-            w = w + 1;
245
-            // each time through the inner loop
246
-        
247 313
         System.out.print("The Sum is ");
248 314
         System.out.println(sumOfThrees);
249 315
 
@@ -256,11 +322,10 @@ public class WriteLoops {
256 322
         int w = 0;
257 323
         int sumOfThrees = 0;
258 324
 
259
- 
260
-            // calling
261
-            w = w + 1;
262
-            // each time through the inner loop
263
-        
325
+        // calling
326
+        w = w + 1;
327
+        // each time through the inner loop
328
+
264 329
         System.out.print("The Sum is ");
265 330
         System.out.println(sumOfThrees);
266 331
 
@@ -279,11 +344,11 @@ public class WriteLoops {
279 344
         boolean onTime = true;
280 345
 
281 346
         // ADD YOUR CODE here.
282
- 
283
-            // be sure to call
284
-            w = w + 1;
285
-            // each time inside the loop
286
-        
347
+
348
+        // be sure to call
349
+        w = w + 1;
350
+        // each time inside the loop
351
+
287 352
         return w;
288 353
     }
289 354
 
@@ -296,11 +361,10 @@ public class WriteLoops {
296 361
         int w = 0;
297 362
         int numberOfVotes = voteTallies.length;
298 363
 
299
- 
300
-            // calling
301
-            w = w + 1;
302
-            // each time through the inner loop
303
-        
364
+        // calling
365
+        w = w + 1;
366
+        // each time through the inner loop
367
+
304 368
         return w;
305 369
     }
306 370
 
@@ -311,11 +375,10 @@ public class WriteLoops {
311 375
         int w = 0;
312 376
         int numberOfVotes = voteTallies.length;
313 377
 
378
+        // calling
379
+        w = w + 1;
380
+        // each time through the inner loop
314 381
 
315
-            // calling
316
-            w = w + 1;
317
-            // each time through the inner loop
318
-        
319 382
         return w;
320 383
     }
321 384
 
@@ -378,14 +441,15 @@ public class WriteLoops {
378 441
     //         return (i >= 3);
379 442
     //     };
380 443
     // };
381
-        private int summer = 0;
382
-        private boolean isSummer() {
383
-            if (summer == 3) {
384
-                return true;
385
-            }
386
-            summer++;
387
-            return false;
444
+    private int summer = 0;
445
+    private boolean isSummer() {
446
+        if (summer == 3) {
447
+            return true;
388 448
         }
449
+        summer++;
450
+        return false;
451
+    }
452
+
389 453
     private void sendEmergencyText(String mesg, String phone) {
390 454
     }
391 455
 

+ 26
- 26
package.bluej Целия файл

@@ -1,24 +1,24 @@
1 1
 #BlueJ package file
2
-dependency1.from=WriteLoopsTest
3
-dependency1.to=WriteLoops
2
+dependency1.from=WriteIFsTest
3
+dependency1.to=WriteIFs
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=WriteIFsTest
6
-dependency2.to=WriteIFs
5
+dependency2.from=WriteLoopsTest
6
+dependency2.to=WriteLoops
7 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=0
9
+editor.fx.0.width=0
10
+editor.fx.0.x=0
11
+editor.fx.0.y=0
12
+objectbench.height=92
13
+objectbench.width=750
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.847926267281106
16
+package.editor.height=545
17
+package.editor.width=648
18
+package.editor.x=15
19
+package.editor.y=23
20
+package.frame.height=709
21
+package.frame.width=774
22 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true
@@ -44,18 +44,18 @@ target2.type=ClassTarget
44 44
 target2.width=100
45 45
 target2.x=140
46 46
 target2.y=360
47
+target3.association=WriteIFsTest
47 48
 target3.height=110
48
-target3.name=WriteIFsTest
49
+target3.name=WriteIFs
49 50
 target3.showInterface=false
50
-target3.type=UnitTestTargetJunit4
51
+target3.type=ClassTarget
51 52
 target3.width=80
52
-target3.x=180
53
-target3.y=100
54
-target4.association=WriteIFsTest
53
+target3.x=150
54
+target3.y=130
55 55
 target4.height=110
56
-target4.name=WriteIFs
56
+target4.name=WriteIFsTest
57 57
 target4.showInterface=false
58
-target4.type=ClassTarget
58
+target4.type=UnitTestTargetJunit4
59 59
 target4.width=80
60
-target4.x=150
61
-target4.y=130
60
+target4.x=180
61
+target4.y=100