#39 First Saturday zmalone97

Открыто
zmalone хочет смерджить 1 коммит(ов) из zmalone/FirstSaturday:master в master
4 измененных файлов: 207 добавлений и 125 удалений
  1. 48
    31
      WriteIFs.java
  2. 3
    3
      WriteIFsTest.java
  3. 141
    76
      WriteLoops.java
  4. 15
    15
      package.bluej

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

@@ -7,20 +7,25 @@
7 7
  */
8 8
 public class WriteIFs
9 9
 {
10
- 
10
+
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
-     
14
+        if(!player1){
15
+            displayGameOver(player1);
16
+        }
17
+
15 18
     }
16
-    
19
+
17 20
     public String thermoSTAT(int room) {
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()”
21
-
22
-
23
-        
24
+        if (tempurature(room)<70){
25
+            heatOn();
26
+        }else{
27
+            coolOn();
28
+        }
24 29
         return this.ss;
25 30
     }
26 31
 
@@ -30,16 +35,19 @@ public class WriteIFs
30 35
         // AND 
31 36
         // “insideTemp()” is less than 62, 
32 37
         // calls “startAFire(fireplace1)”
33
-
34
-    }
38
+        if(outsideTemp()<50 && insideTemp()<62){
39
+            startAFire(fireplace1);
40
+        }
41
+}
35 42
 
36 43
     public void checkFuel(double fuelLevel) {
37 44
         // Write an IF statement that checks “fuelLevel” 
38 45
         // and if that check is less than 0.08, calls “refuel()”
39
-
46
+        if(fuelLevel<0.08){
47
+            refuel();
48
+        }
40 49
     }
41 50
 
42
-
43 51
     
44 52
     /**
45 53
      *  Pay no attention to the code below this point.
@@ -47,53 +55,62 @@ public class WriteIFs
47 55
      * 
48 56
      * instance variables
49 57
      * / 
50
-   int x;
51
-   int tt_t;
52
-   int tt_s;
53
-   int oo1, oo2;
54
-   String ss;
55
-
56
-
57
-  /**
58
-   * Constructor for objects of class WriteIFs
59
-   */
60
-  public WriteIFs()
61
-  {
62
-      // initialise instance variables
63
-      x = 0;
64
-      tt_t = 0;
65
-      tt_s = 1;
66
-      ss = "";
67
-      oo1 = 61;
68
-      oo2 = 49;
69
-  }
58
+
59
+
60
+    /**
61
+     * Constructor for objects of class WriteIFs
62
+     */
63
+
64
+    int x;
65
+    int tt_t;
66
+    int tt_s;
67
+    int oo1, oo2;
68
+    String ss;
69
+
70
+    public WriteIFs()
71
+    {
72
+        // initialise instance variables
73
+        x = 0;
74
+        tt_t = 0;
75
+        tt_s = 1;
76
+        ss = "";
77
+        oo1 = 61;
78
+        oo2 = 49;
79
+    }
70 80
 
71 81
     // associated routines
72 82
     public boolean isAlive(boolean p) {
73 83
         return !p;
74 84
     }
85
+
75 86
     private int tempurature(int t) {
76 87
         return t+2;
77 88
     }
89
+
78 90
     private void heatOn() {
79 91
         this.ss = "heating";
80 92
     }
93
+
81 94
     private void coolOn() {
82 95
         this.ss = "cooling";
83 96
     }
84
- 
97
+
85 98
     private int insideTemp() {
86 99
         return oo1;
87 100
     }
101
+
88 102
     private int outsideTemp() {
89 103
         return oo2;
90 104
     }
105
+
91 106
     private void startAFire(Object o) {
92 107
         this.tt_s = 213;
93 108
     }
109
+
94 110
     private void refuel() {
95 111
         this.x = 99;
96 112
     }
113
+
97 114
     private void displayGameOver(boolean b) {
98 115
         this.ss = "Game Over!";
99 116
     }

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

@@ -47,7 +47,7 @@ public class WriteIFsTest
47 47
     public void TestIfs()
48 48
     {
49 49
         WriteIFs writeIFs1 = new WriteIFs();
50
-        writeIFs1.playerDied(true);
50
+        writeIFs1.playerDied(false);
51 51
         assertEquals("Game Over!", writeIFs1.ss);
52 52
     }
53 53
 
@@ -95,7 +95,7 @@ public class WriteIFsTest
95 95
         writeIFs1.oo1 = 65;
96 96
         writeIFs1.tt_s = 1;
97 97
         writeIFs1.fireplaceControl(oo);
98
-        assertEquals(213, writeIFs1.tt_s);
98
+        assertEquals(1, writeIFs1.tt_s);
99 99
     }
100 100
     @Test
101 101
     public void TestFireControl3()
@@ -105,7 +105,7 @@ public class WriteIFsTest
105 105
         writeIFs1.oo2 = 80;
106 106
         writeIFs1.tt_s = 1;
107 107
         writeIFs1.fireplaceControl(oo);
108
-        assertEquals(213, writeIFs1.tt_s);
108
+        assertEquals(1, writeIFs1.tt_s);
109 109
     }
110 110
 
111 111
 }

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

@@ -18,12 +18,15 @@ 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
+        // Write a FOR loop that counts from 1 to 5.
22
+        // calling
23
+        //w = w + 1;
24
+        // each time through the loop
25 25
 
26 26
         // this will tell the test how many times the loop executed.
27
+        for(int i=0; i<5; i++){
28
+            w= w + 1;
29
+        }
27 30
         return w;
28 31
     }
29 32
 
@@ -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=0; i<10; i++){
41
+            w= w + 1;
42
+        }
43
+
38 44
         return w;
39 45
     }
40 46
 
@@ -45,7 +51,9 @@ 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<31; i++){
55
+            w = w + 1;
56
+        }
49 57
         return w;
50 58
     }
51 59
 
@@ -54,9 +62,11 @@ public class WriteLoops {
54 62
 
55 63
         // Write a FOR loop that counts down from 100 to 0.
56 64
         // calling
57
-        w = w + 1;
65
+        //w = w + 1;
58 66
         // each time through the loop
59
-        
67
+        for(int i=100; i > 0; i--){
68
+            w= w+1;
69
+        }
60 70
         return w;
61 71
     }
62 72
 
@@ -65,8 +75,11 @@ public class WriteLoops {
65 75
 
66 76
         // Write a FOR loop from 0 to 32 by 2s.
67 77
         // calling
68
-        w = w + 1;
78
+        //w = w + 1;
69 79
         // each time through the loop
80
+        for(int i = 0; i>32; i+=2){
81
+            w= w+1;
82
+        }
70 83
         return w;
71 84
     }
72 85
 
@@ -75,9 +88,11 @@ public class WriteLoops {
75 88
 
76 89
         // Write a FOR loop from 1 to less than 5001 by 11s.
77 90
         // calling
78
-        w = w + 1;
91
+        //w = w + 1;
79 92
         // each time through the loop
80
-        
93
+        for(int i = 1; i<5001; i+=11){
94
+            w= w+1;
95
+        }
81 96
         return w;
82 97
     }
83 98
 
@@ -86,9 +101,15 @@ public class WriteLoops {
86 101
 
87 102
         // Write a nested FOR loop(s), where one counts from
88 103
         // 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
104
+        // calling
105
+        // w = w + 1;
106
+        // each time through the inner loop
107
+        for(int i=0; i<20; i++){
108
+            for(int z=0; z<4; z++){
109
+                w= w+1;
110
+            }
111
+            w= w+1;
112
+        }
92 113
 
93 114
         return w;
94 115
     }
@@ -101,12 +122,18 @@ public class WriteLoops {
101 122
         // loop index counter and if it’s greater than 51,
102 123
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103 124
 
104
-                // calling
105
-                w = w + 1;
106
-            // each time through the inner loop
107
-        
108
-        return w;
125
+        // calling
126
+        //  w = w + 1;
127
+        // each time through the inner loop
128
+        for(int i=5; i<105; i++){
129
+            if(i>51){
130
+                    System.out.print("Hello Zipcode");
131
+                }else{
132
+                    w= w+1;
133
+        }
109 134
     }
135
+    return w;
136
+}
110 137
 
111 138
     public void simpleLoops() {
112 139
         int i = 0;
@@ -134,12 +161,17 @@ public class WriteLoops {
134 161
 
135 162
         // you need to use a .equals for two Strings.
136 163
 
137
-            // calling
138
-            w = w + 1;
139
-            // each time through the inner loop
164
+        // calling
165
+        //w = w + 1;
166
+        // each time through the inner loop
140 167
         
168
+        while (gpsCurrentLocation()!= "Home"){
169
+        driveSomeMore();
170
+        w=w+1;
171
+        } 
172
+        System.out.println("Honey, I'm Home");
141 173
 
142
-            return w;
174
+        return w;
143 175
     }
144 176
 
145 177
     // Getting harder...
@@ -155,11 +187,15 @@ public class WriteLoops {
155 187
         int runningScore = 0;
156 188
 
157 189
         // do your while loop here
158
- 
159
-            // calling
160
-            w = w + 1;
161
-            // each time through the inner loop
190
+
191
+        // calling
192
+        //w = w + 1;
193
+        // each time through the inner loop
194
+        while(runningScore<highestScore){
195
+        runningScore=currentScore+runningScore;
196
+        w=w+1;
162 197
         
198
+        }
163 199
         return w; // >= 3;
164 200
     }
165 201
 
@@ -173,10 +209,15 @@ public class WriteLoops {
173 209
 
174 210
         // do your while loop here
175 211
 
176
-            // calling
177
-            w = w + 1;
178
-            // each time through the inner loop
179
-
212
+        // calling
213
+        //w = w + 1;
214
+        // each time through the inner loop
215
+        do{
216
+        runningScore=runningScore+currentScore;
217
+        w=w+1;
218
+        
219
+        }while(runningScore<highestScore);
220
+        
180 221
         return w >= 3;
181 222
     }
182 223
 
@@ -187,12 +228,17 @@ public class WriteLoops {
187 228
     public int checkServerStatus() {
188 229
         int w = 0;
189 230
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
191 231
 
192 232
         // calling
193
-        w = w + 1;
233
+        //w = w + 1;
194 234
         // each time through the inner loop
195
-        
235
+        while(serverIsRunning()){
236
+        waitFor(5);
237
+        w= w+1;
238
+        }
239
+        if(!serverIsRunning()){
240
+        sendEmergencyText("Help!",adminPhoneNumber);
241
+        }
196 242
         return w;
197 243
     }
198 244
 
@@ -201,12 +247,14 @@ public class WriteLoops {
201 247
     // and if it is, add 7 to “i”
202 248
     public int loop50by7() {
203 249
         int w = 0;
204
-
205
-
206
-            // calling
207
-            w = w + 1;
208
-            // each time through the inner loop
209
-        
250
+        int i=7;
251
+        // calling
252
+        w = w + 1;
253
+        // each time through the inner loop
254
+        while(i<50){
255
+        i= 7+i;
256
+        w=w+1;
257
+        }
210 258
         return w;
211 259
     }
212 260
 
@@ -239,11 +287,14 @@ public class WriteLoops {
239 287
         int w = 0;
240 288
         int sumOfThrees = 0;
241 289
 
242
- 
243
-            // calling
244
-            w = w + 1;
245
-            // each time through the inner loop
246
-        
290
+        // calling
291
+        w = w + 1;
292
+        // each time through the inner loop
293
+        //for(int i=sumOfThrees; i:)
294
+        for(int i=0; i<threes_array.length; i++){
295
+        sumOfThrees = sumOfThrees + threes_array[i];
296
+        w=w+1;
297
+        }
247 298
         System.out.print("The Sum is ");
248 299
         System.out.println(sumOfThrees);
249 300
 
@@ -255,12 +306,14 @@ public class WriteLoops {
255 306
     public int rewriteFooAsWhile() {
256 307
         int w = 0;
257 308
         int sumOfThrees = 0;
258
-
259
- 
260
-            // calling
261
-            w = w + 1;
262
-            // each time through the inner loop
263
-        
309
+        int i= 0;
310
+        // calling
311
+        w = w + 1;
312
+        // each time through the inner loop
313
+        while(i<threes_array.length){
314
+        sumOfThrees = sumOfThrees + threes_array[i];
315
+        w=w+1;
316
+        }
264 317
         System.out.print("The Sum is ");
265 318
         System.out.println(sumOfThrees);
266 319
 
@@ -277,13 +330,19 @@ public class WriteLoops {
277 330
     public int manageYardAndJunior() {
278 331
         int w = 0;
279 332
         boolean onTime = true;
280
-
333
+        boolean yardNeedsMowed = true;
281 334
         // ADD YOUR CODE here.
282
- 
283
-            // be sure to call
284
-            w = w + 1;
285
-            // each time inside the loop
286
-        
335
+
336
+        // be sure to call
337
+        //w = w + 1;
338
+        // each time inside the loop
339
+        while(isSummer()){
340
+        if(yardNeedsMowed){
341
+        yellAtJuniorToMowLawn();
342
+        }
343
+        w=w+1;
344
+        }
345
+
287 346
         return w;
288 347
     }
289 348
 
@@ -295,12 +354,15 @@ public class WriteLoops {
295 354
     public int tallyVote1() {
296 355
         int w = 0;
297 356
         int numberOfVotes = voteTallies.length;
298
-
299
- 
300
-            // calling
301
-            w = w + 1;
302
-            // each time through the inner loop
303 357
         
358
+        // calling
359
+        w = w + 1;
360
+        // each time through the inner loop
361
+        for(int i=0; i<numberOfVotes; i++){
362
+        System.out.println(voteTallies.toString());
363
+        w=w+1;
364
+        
365
+        }
304 366
         return w;
305 367
     }
306 368
 
@@ -310,12 +372,14 @@ public class WriteLoops {
310 372
     public int tallyVote2() {
311 373
         int w = 0;
312 374
         int numberOfVotes = voteTallies.length;
313
-
314
-
315
-            // calling
316
-            w = w + 1;
317
-            // each time through the inner loop
318
-        
375
+        int i = 0;
376
+        // calling
377
+        w = w + 1;
378
+        // each time through the inner loop
379
+        while(i<numberOfVotes){
380
+        System.out.println(voteTallies.toString());
381
+        w=w+1;
382
+        }
319 383
         return w;
320 384
     }
321 385
 
@@ -378,14 +442,15 @@ public class WriteLoops {
378 442
     //         return (i >= 3);
379 443
     //     };
380 444
     // };
381
-        private int summer = 0;
382
-        private boolean isSummer() {
383
-            if (summer == 3) {
384
-                return true;
385
-            }
386
-            summer++;
387
-            return false;
445
+    private int summer = 0;
446
+    private boolean isSummer() {
447
+        if (summer == 3) {
448
+            return true;
388 449
         }
450
+        summer++;
451
+        return false;
452
+    }
453
+
389 454
     private void sendEmergencyText(String mesg, String phone) {
390 455
     }
391 456
 

+ 15
- 15
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 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
12
-objectbench.height=101
13
-objectbench.width=740
10
+editor.fx.0.x=240
11
+editor.fx.0.y=24
12
+objectbench.height=93
13
+objectbench.width=665
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.849624060150376
16
+package.editor.height=558
17
+package.editor.width=563
18
+package.editor.x=15
19
+package.editor.y=23
20
+package.frame.height=723
21
+package.frame.width=689
22 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true