#36 William Brown First Saturday

開啟中
WJB3003 請求將 2 次程式碼提交從 WJB3003/FirstSaturday:master 合併至 master
共有 5 個檔案被更改,包括 148 行新增87 行删除
  1. 33
    21
      WriteIFs.java
  2. 9
    2
      WriteIFsTest.java
  3. 82
    40
      WriteLoops.java
  4. 3
    3
      WriteLoopsTest.java
  5. 21
    21
      package.bluej

+ 33
- 21
WriteIFs.java 查看文件

2
 /**
2
 /**
3
  * Write a description of class WriteIFs here.
3
  * Write a description of class WriteIFs here.
4
  *
4
  *
5
- * @author (your name)
6
- * @version (a version number or a date)
5
+ * @author William Brown
6
+ * @version 1.0 10/21/2018
7
  */
7
  */
8
 public class WriteIFs
8
 public class WriteIFs
9
 {
9
 {
10
+   int x;
11
+   int tt_t;
12
+   int tt_s;
13
+   int oo1, oo2;
14
+   String ss;
15
+   
16
+   public WriteIFs()
17
+  {
18
+      // initialise instance variables
19
+      x = 0;
20
+      tt_t = 0;
21
+      tt_s = 1;
22
+      ss = "";
23
+      oo1 = 61;
24
+      oo2 = 49;
25
+  }
10
  
26
  
11
     public void playerDied(boolean player1) {
27
     public void playerDied(boolean player1) {
12
         // Write an IF statement that checks “player1.isAlive()” 
28
         // Write an IF statement that checks “player1.isAlive()” 
29
+        if(player1 == true){
30
+            displayGameOver(player1);
31
+        }
13
         // and if that’s false, calls “displayGameOver(player1)”
32
         // and if that’s false, calls “displayGameOver(player1)”
14
-     
15
     }
33
     }
16
     
34
     
17
     public String thermoSTAT(int room) {
35
     public String thermoSTAT(int room) {
18
         // Write an IF statement that checks the 
36
         // Write an IF statement that checks the 
19
         // “temperature(room)” and if that check is less than 70, 
37
         // “temperature(room)” and if that check is less than 70, 
20
         // calls “heatOn()” else calls “coolOn()”
38
         // calls “heatOn()” else calls “coolOn()”
21
-
22
-
23
-        
39
+        if(tempurature(room) < 70){
40
+            heatOn();
41
+        } else{
42
+            coolOn();
43
+        }
24
         return this.ss;
44
         return this.ss;
25
     }
45
     }
26
 
46
 
30
         // AND 
50
         // AND 
31
         // “insideTemp()” is less than 62, 
51
         // “insideTemp()” is less than 62, 
32
         // calls “startAFire(fireplace1)”
52
         // calls “startAFire(fireplace1)”
33
-
53
+        if(outsideTemp() < 50 || insideTemp() < 62){
54
+            startAFire(fireplace1);
55
+        }
34
     }
56
     }
35
 
57
 
36
     public void checkFuel(double fuelLevel) {
58
     public void checkFuel(double fuelLevel) {
37
         // Write an IF statement that checks “fuelLevel” 
59
         // Write an IF statement that checks “fuelLevel” 
38
         // and if that check is less than 0.08, calls “refuel()”
60
         // and if that check is less than 0.08, calls “refuel()”
39
-
61
+        if(fuelLevel < 0.08){
62
+            refuel();
63
+        }
40
     }
64
     }
41
 
65
 
42
 
66
 
46
      * 
70
      * 
47
      * 
71
      * 
48
      * instance variables
72
      * instance variables
49
-     * / 
73
+  
50
    int x;
74
    int x;
51
    int tt_t;
75
    int tt_t;
52
    int tt_s;
76
    int tt_s;
54
    String ss;
78
    String ss;
55
 
79
 
56
 
80
 
57
-  /**
58
    * Constructor for objects of class WriteIFs
81
    * Constructor for objects of class WriteIFs
59
    */
82
    */
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
-  }
70
 
83
 
71
     // associated routines
84
     // associated routines
72
     public boolean isAlive(boolean p) {
85
     public boolean isAlive(boolean p) {
81
     private void coolOn() {
94
     private void coolOn() {
82
         this.ss = "cooling";
95
         this.ss = "cooling";
83
     }
96
     }
84
- 
85
     private int insideTemp() {
97
     private int insideTemp() {
86
         return oo1;
98
         return oo1;
87
     }
99
     }

+ 9
- 2
WriteIFsTest.java 查看文件

8
 /**
8
 /**
9
  * The test class WriteIFsTest.
9
  * The test class WriteIFsTest.
10
  *
10
  *
11
- * @author  kyounger
12
- * @version 1.2
11
+ * @author  William Brown
12
+ * @version 1.3 10/21/2018
13
  */
13
  */
14
 public class WriteIFsTest
14
 public class WriteIFsTest
15
 {
15
 {
16
+   int x;
17
+   int tt_t;
18
+   int tt_s;
19
+   int oo1, oo2;
20
+   String ss;
21
+    
16
     private static final double _0_5 = 0.5;
22
     private static final double _0_5 = 0.5;
17
     private static final double _0_04 = 0.04;
23
     private static final double _0_04 = 0.04;
18
 
24
 
112
 
118
 
113
 
119
 
114
 
120
 
121
+

+ 82
- 40
WriteLoops.java 查看文件

7
 /**
7
 /**
8
  * Writeloops get you thinking about how to do different things with loops.
8
  * Writeloops get you thinking about how to do different things with loops.
9
  *
9
  *
10
- * @author anonymous coward
10
+ * @author William Brown
11
  * @version -0.3
11
  * @version -0.3
12
  * 
12
  * 
13
  */
13
  */
17
 
17
 
18
     public int oneToFive() {
18
     public int oneToFive() {
19
         int w = 0;
19
         int w = 0;
20
-
21
         // Write a FOR loop that counts from 1 to 10.
20
         // Write a FOR loop that counts from 1 to 10.
22
             // calling
21
             // calling
23
-            w = w + 1;
24
             // each time through the loop
22
             // each time through the loop
25
-
23
+        for(int i = 1; i<= 5; i++){
24
+            w = w + 1;
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
         return w;
27
         return w;
28
     }
28
     }
29
 
29
 
30
     public int oneToTen() {
30
     public int oneToTen() {
31
         int w = 0;
31
         int w = 0;
32
-
33
         // Write a FOR loop that counts from 1 to 10.
32
         // Write a FOR loop that counts from 1 to 10.
34
         // calling
33
         // calling
35
-        w = w + 1;
34
+        for(int i = 1; i <= 10; i++){
35
+            w = w + 1;
36
+        }
36
         // each time through the loop
37
         // each time through the loop
37
         
38
         
38
         return w;
39
         return w;
43
 
44
 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
46
         // calling
46
-        w = w + 1;
47
+        for(int i = 21; i <= 31; i++){
48
+            w = w + 1;
49
+        }
47
         // each time through the loop
50
         // each time through the loop
48
         
51
         
49
         return w;
52
         return w;
54
 
57
 
55
         // Write a FOR loop that counts down from 100 to 0.
58
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
59
         // calling
57
-        w = w + 1;
60
+        for(int i = 100; i > 0; i --){
61
+            w = w + 1;
62
+        }
58
         // each time through the loop
63
         // each time through the loop
59
         
64
         
60
         return w;
65
         return w;
65
 
70
 
66
         // Write a FOR loop from 0 to 32 by 2s.
71
         // Write a FOR loop from 0 to 32 by 2s.
67
         // calling
72
         // calling
68
-        w = w + 1;
73
+        for(int i = 0; i <= 32; i +=2){
74
+            w = w + 1;
75
+        }
69
         // each time through the loop
76
         // each time through the loop
70
         return w;
77
         return w;
71
     }
78
     }
75
 
82
 
76
         // Write a FOR loop from 1 to less than 5001 by 11s.
83
         // Write a FOR loop from 1 to less than 5001 by 11s.
77
         // calling
84
         // calling
78
-        w = w + 1;
85
+        for(int i = 1; i < 5001; i += 11){
86
+            w = w + 1;
87
+        }
79
         // each time through the loop
88
         // each time through the loop
80
         
89
         
81
         return w;
90
         return w;
87
         // Write a nested FOR loop(s), where one counts from
96
         // 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
97
         // 0 to less than 20 and the inner one counts from 0 to 4
89
                 // calling
98
                 // calling
99
+        for(int i = 0; i < 20; i++){
100
+            for(int j = 0; j <= 4; j++){
90
                 w = w + 1;
101
                 w = w + 1;
102
+            }
103
+        }
91
                 // each time through the inner loop
104
                 // each time through the inner loop
92
 
105
 
93
         return w;
106
         return w;
102
         // prints “Hello Zipcode” instead of the statement w = w + 1;
115
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103
 
116
 
104
                 // calling
117
                 // calling
118
+        for(int i = 5; i < 105; i++){
119
+            if(i > 51){
120
+                System.out.println("Hello Zipcode");
121
+            } else {
105
                 w = w + 1;
122
                 w = w + 1;
123
+            }
124
+        }
106
             // each time through the inner loop
125
             // each time through the inner loop
107
         
126
         
108
         return w;
127
         return w;
133
         int w = 0;
152
         int w = 0;
134
 
153
 
135
         // you need to use a .equals for two Strings.
154
         // you need to use a .equals for two Strings.
136
-
155
+            while(!gpsCurrentLocation().equals("Home")){
156
+                    driveSomeMore();
157
+                    w = w + 1;
158
+            }
159
+            System.out.println("Honey, I'm Home");
137
             // calling
160
             // calling
138
-            w = w + 1;
139
             // each time through the inner loop
161
             // each time through the inner loop
140
-        
141
-
142
             return w;
162
             return w;
143
     }
163
     }
144
 
164
 
155
         int runningScore = 0;
175
         int runningScore = 0;
156
 
176
 
157
         // do your while loop here
177
         // do your while loop here
158
- 
178
+        while(runningScore < highestScore){
179
+            runningScore += currentScore;
180
+            gameNextScore();
159
             // calling
181
             // calling
160
             w = w + 1;
182
             w = w + 1;
161
             // each time through the inner loop
183
             // each time through the inner loop
162
-        
184
+        }
163
         return w; // >= 3;
185
         return w; // >= 3;
164
     }
186
     }
165
 
187
 
172
         int runningScore = 0;
194
         int runningScore = 0;
173
 
195
 
174
         // do your while loop here
196
         // do your while loop here
175
-
197
+            do{
198
+                runningScore += currentScore;
199
+            gameNextScore();
176
             // calling
200
             // calling
177
             w = w + 1;
201
             w = w + 1;
202
+           }while(runningScore < highestScore);
178
             // each time through the inner loop
203
             // each time through the inner loop
179
 
204
 
180
         return w >= 3;
205
         return w >= 3;
187
     public int checkServerStatus() {
212
     public int checkServerStatus() {
188
         int w = 0;
213
         int w = 0;
189
         String adminPhoneNumber = "+1 202 456 1111";
214
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
215
+        while(serverIsRunning() == true){
216
+            waitFor(5);
217
+            w = w + 1;
218
+        }
219
+        if(serverIsRunning() == false){
220
+            sendEmergencyText("Help!", adminPhoneNumber);
221
+            tryServerRestart("Help!", adminPhoneNumber);
222
+        }
191
 
223
 
192
         // calling
224
         // calling
193
-        w = w + 1;
194
         // each time through the inner loop
225
         // each time through the inner loop
195
         
226
         
196
         return w;
227
         return w;
200
     // Write a WHILE loop that checks “i” is less than 50,
231
     // Write a WHILE loop that checks “i” is less than 50,
201
     // and if it is, add 7 to “i”
232
     // and if it is, add 7 to “i”
202
     public int loop50by7() {
233
     public int loop50by7() {
203
-        int w = 0;
204
-
205
-
234
+        int i = 7;
235
+            while(i < 50){
206
             // calling
236
             // calling
207
-            w = w + 1;
237
+            i = i + 7;
208
             // each time through the inner loop
238
             // each time through the inner loop
209
-        
210
-        return w;
239
+        }
240
+        return i;
211
     }
241
     }
212
 
242
 
213
     int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
243
     int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
220
         int sumOfThrees = 0;
250
         int sumOfThrees = 0;
221
 
251
 
222
         // this is a so called Enhanced for loop
252
         // this is a so called Enhanced for loop
223
-        for (int index : threes_array) {
224
-            sumOfThrees = sumOfThrees + threes_array[index];
253
+        for (int i = 0; i < threes_array.length; i ++ ) {
254
+            sumOfThrees = sumOfThrees + threes_array[i];
225
             // calling
255
             // calling
226
             w = w + 1;
256
             w = w + 1;
227
             // each time through the inner loop
257
             // each time through the inner loop
237
     // with 'i' as its index variable.
267
     // with 'i' as its index variable.
238
     public int rewriteFooAsFor() {
268
     public int rewriteFooAsFor() {
239
         int w = 0;
269
         int w = 0;
270
+        // this is an array of ints. it is of length 7 (from 0 -> 6)
240
         int sumOfThrees = 0;
271
         int sumOfThrees = 0;
241
 
272
 
242
- 
273
+        // this is a so called Enhanced for loop
274
+        for (int i = 0; i < threes_array.length; i ++ ) {
275
+            sumOfThrees = sumOfThrees + threes_array[i];
243
             // calling
276
             // calling
244
             w = w + 1;
277
             w = w + 1;
245
             // each time through the inner loop
278
             // each time through the inner loop
246
-        
279
+        }
247
         System.out.print("The Sum is ");
280
         System.out.print("The Sum is ");
248
         System.out.println(sumOfThrees);
281
         System.out.println(sumOfThrees);
249
 
282
 
255
     public int rewriteFooAsWhile() {
288
     public int rewriteFooAsWhile() {
256
         int w = 0;
289
         int w = 0;
257
         int sumOfThrees = 0;
290
         int sumOfThrees = 0;
258
-
259
- 
291
+        int i = 0;
292
+        while(i < threes_array.length){
293
+            sumOfThrees = sumOfThrees + threes_array[i];
260
             // calling
294
             // calling
261
             w = w + 1;
295
             w = w + 1;
262
             // each time through the inner loop
296
             // each time through the inner loop
263
-        
297
+            i++;
298
+        }
264
         System.out.print("The Sum is ");
299
         System.out.print("The Sum is ");
265
         System.out.println(sumOfThrees);
300
         System.out.println(sumOfThrees);
266
 
301
 
277
     public int manageYardAndJunior() {
312
     public int manageYardAndJunior() {
278
         int w = 0;
313
         int w = 0;
279
         boolean onTime = true;
314
         boolean onTime = true;
315
+        boolean yardNeedsMowed = true;
280
 
316
 
281
         // ADD YOUR CODE here.
317
         // ADD YOUR CODE here.
282
- 
318
+        while(isSummer()){
283
             // be sure to call
319
             // be sure to call
320
+            if(yardNeedsMowed == true){
321
+                yellAtJuniorToMowLawn();
322
+            }
284
             w = w + 1;
323
             w = w + 1;
285
             // each time inside the loop
324
             // each time inside the loop
286
-        
325
+        }
326
+        sendJuniorBackToSchool("so boring");
287
         return w;
327
         return w;
288
     }
328
     }
289
 
329
 
295
     public int tallyVote1() {
335
     public int tallyVote1() {
296
         int w = 0;
336
         int w = 0;
297
         int numberOfVotes = voteTallies.length;
337
         int numberOfVotes = voteTallies.length;
298
-
299
- 
338
+        for(int i = 0; i < numberOfVotes; i++){
300
             // calling
339
             // calling
340
+            System.out.println(voteTallies[i]);
301
             w = w + 1;
341
             w = w + 1;
302
             // each time through the inner loop
342
             // each time through the inner loop
303
-        
343
+        }
304
         return w;
344
         return w;
305
     }
345
     }
306
 
346
 
310
     public int tallyVote2() {
350
     public int tallyVote2() {
311
         int w = 0;
351
         int w = 0;
312
         int numberOfVotes = voteTallies.length;
352
         int numberOfVotes = voteTallies.length;
313
-
314
-
353
+        int idx = 0;
354
+        while( idx < numberOfVotes ){
315
             // calling
355
             // calling
356
+            System.out.println(voteTallies[idx]);
357
+            idx++;
316
             w = w + 1;
358
             w = w + 1;
317
             // each time through the inner loop
359
             // each time through the inner loop
318
-        
360
+        }
319
         return w;
361
         return w;
320
     }
362
     }
321
 
363
 

+ 3
- 3
WriteLoopsTest.java 查看文件

8
 /**
8
 /**
9
  * The test class WriteLoopsTest.
9
  * The test class WriteLoopsTest.
10
  *
10
  *
11
- * @author  kyounger
12
- * @version 1.2
11
+ * @author  William Brown
12
+ * @version 1.3
13
  */
13
  */
14
 public class WriteLoopsTest
14
 public class WriteLoopsTest
15
 {
15
 {
71
     public void Test2to32()
71
     public void Test2to32()
72
     {
72
     {
73
         WriteLoops writeLoo1 = new WriteLoops();
73
         WriteLoops writeLoo1 = new WriteLoops();
74
-        assertEquals(0, writeLoo1.byTwoTo32());
74
+        assertEquals(17, writeLoo1.byTwoTo32());
75
     }
75
     }
76
 
76
 
77
     @Test
77
     @Test

+ 21
- 21
package.bluej 查看文件

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
8
+editor.fx.0.height=711
9
 editor.fx.0.width=800
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=480
11
+editor.fx.0.y=23
12
+objectbench.height=91
13
+objectbench.width=455
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.8499234303215927
16
+package.editor.height=548
17
+package.editor.width=353
18
+package.editor.x=0
19
+package.editor.y=23
20
+package.frame.height=711
21
+package.frame.width=479
22
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4
24
 package.showExtends=true
24
 package.showExtends=true
44
 target2.width=100
44
 target2.width=100
45
 target2.x=140
45
 target2.x=140
46
 target2.y=360
46
 target2.y=360
47
+target3.association=WriteIFsTest
47
 target3.height=110
48
 target3.height=110
48
-target3.name=WriteIFsTest
49
+target3.name=WriteIFs
49
 target3.showInterface=false
50
 target3.showInterface=false
50
-target3.type=UnitTestTargetJunit4
51
+target3.type=ClassTarget
51
 target3.width=80
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
 target4.height=110
55
 target4.height=110
56
-target4.name=WriteIFs
56
+target4.name=WriteIFsTest
57
 target4.showInterface=false
57
 target4.showInterface=false
58
-target4.type=ClassTarget
58
+target4.type=UnitTestTargetJunit4
59
 target4.width=80
59
 target4.width=80
60
-target4.x=150
61
-target4.y=130
60
+target4.x=180
61
+target4.y=100