Преглед на файлове

Write Loops completed, stuck on WriteIFs and it's test

William Brown преди 6 години
родител
ревизия
b1a46a1951
променени са 5 файла, в които са добавени 141 реда и са изтрити 79 реда
  1. 23
    10
      WriteIFs.java
  2. 12
    5
      WriteIFsTest.java
  3. 82
    40
      WriteLoops.java
  4. 2
    2
      WriteLoopsTest.java
  5. 22
    22
      package.bluej

+ 23
- 10
WriteIFs.java Целия файл

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

+ 12
- 5
WriteIFsTest.java Целия файл

@@ -8,11 +8,17 @@ import org.junit.Test;
8 8
 /**
9 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 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 22
     private static final double _0_5 = 0.5;
17 23
     private static final double _0_04 = 0.04;
18 24
 
@@ -48,7 +54,7 @@ public class WriteIFsTest
48 54
     {
49 55
         WriteIFs writeIFs1 = new WriteIFs();
50 56
         writeIFs1.playerDied(true);
51
-        assertEquals("Game Over!", writeIFs1.ss);
57
+        assertEquals("Game Over!", writeIFs1);
52 58
     }
53 59
 
54 60
 
@@ -69,14 +75,14 @@ public class WriteIFsTest
69 75
     {
70 76
         WriteIFs writeIFs1 = new WriteIFs();
71 77
         writeIFs1.checkFuel(_0_5);
72
-        assertEquals(0, writeIFs1.x);
78
+        assertEquals(0, writeIFs1);
73 79
     }
74 80
     @Test
75 81
     public void TestCheckFuel2()
76 82
     {
77 83
         WriteIFs writeIFs1 = new WriteIFs();
78 84
         writeIFs1.checkFuel(_0_04);
79
-        assertEquals(99, writeIFs1.x);
85
+        assertEquals(99, writeIFs1);
80 86
     }
81 87
     @Test
82 88
     public void TestFireControl()
@@ -112,3 +118,4 @@ public class WriteIFsTest
112 118
 
113 119
 
114 120
 
121
+

+ 82
- 40
WriteLoops.java Целия файл

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

+ 2
- 2
WriteLoopsTest.java Целия файл

@@ -8,8 +8,8 @@ import org.junit.Test;
8 8
 /**
9 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 14
 public class WriteLoopsTest
15 15
 {

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

@@ -5,20 +5,20 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=WriteIFsTest
6 6
 dependency2.to=WriteIFs
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=711
9
+editor.fx.0.width=829
10
+editor.fx.0.x=451
11
+editor.fx.0.y=23
12
+objectbench.height=91
13
+objectbench.width=720
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.8499234303215927
16
+package.editor.height=548
17
+package.editor.width=618
18
+package.editor.x=0
19
+package.editor.y=23
20
+package.frame.height=711
21
+package.frame.width=744
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