Seth 6 年 前
コミット
ef01242ff3
共有3 個のファイルを変更した144 個の追加56 個の削除を含む
  1. 38
    23
      WriteIFs.java
  2. 66
    33
      WriteLoops.java
  3. 40
    0
      WriteLoopsTest.java

+ 38
- 23
WriteIFs.java ファイルの表示

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

+ 66
- 33
WriteLoops.java ファイルの表示

@@ -97,9 +97,9 @@ public class WriteLoops {
97 97
         // Write a nested FOR loop(s), where one counts from
98 98
         // 0 to less than 20 and the inner one counts from 0 to 4
99 99
         // calling
100
-        for(int i=0; i>20; ++i) {
101
-            for(int j=0; j>=4; ++j) {
102
-                w += 1;
100
+        for(int i=0; i<20; ++i) {
101
+            for(int j=0; j<=4; ++j) {
102
+                w = w + 1;
103 103
             }
104 104
         }
105 105
 
@@ -116,14 +116,14 @@ public class WriteLoops {
116 116
         // loop index counter and if it’s greater than 51,
117 117
         // prints “Hello Zipcode” instead of the statement w = w + 1;
118 118
         for(int i=5; i<=105; i++) {
119
-           if(i <= 51){
120
-               w += 1;
119
+            if(i <= 51){
120
+                w += 1;
121 121
             } else {
122 122
                 System.out.println("Hello Zipcode");
123 123
             }
124 124
         }
125 125
         // calling
126
-        
126
+
127 127
         // each time through the inner loop
128 128
 
129 129
         return w;
@@ -156,16 +156,16 @@ public class WriteLoops {
156 156
         // you need to use a .equals for two Strings.
157 157
         while(gpsCurrentLocation().equals("Home") == false){
158 158
             if(w<6){
159
-            driveSomeMore();
160
-            w++;
159
+                driveSomeMore();
160
+                w++;
161 161
             } else {
162
-            gpsCurrentLocation().equals("Home");
162
+                gpsCurrentLocation().equals("Home");
163 163
             }
164 164
         }
165
-        
165
+
166 166
         System.out.println("Honey, I’m Home!");
167 167
         // calling
168
-        
168
+
169 169
         // each time through the inner loop
170 170
 
171 171
         return w;
@@ -182,18 +182,15 @@ public class WriteLoops {
182 182
         int highestScore = 236;
183 183
         int currentScore = gameNextScore();
184 184
         int runningScore = 0;
185
-        
186
-        while(runningScore < currentScore){
187
-             currentScore += runningScore;
188
-             currentScore += gameNextScore();
189
-             w = w + 1;
185
+
186
+        while(runningScore < highestScore){
187
+            runningScore += currentScore;
188
+            currentScore = gameNextScore();
189
+            w = w + 1;
190 190
         }
191 191
         
192
-
193 192
         // calling
194
-        
195 193
         // each time through the inner loop
196
-
197 194
         return w; //>= 3;
198 195
     }
199 196
 
@@ -207,12 +204,13 @@ public class WriteLoops {
207 204
 
208 205
         // do your while loop here
209 206
         do {
210
-            currentScore += runningScore;
211
-            currentScore += gameNextScore();
207
+            runningScore += currentScore;
208
+            currentScore = gameNextScore();
212 209
             w = w + 1;
213 210
         } while(runningScore < highestScore);
214 211
         // calling
215 212
         
213
+
216 214
         // each time through the inner loop
217 215
 
218 216
         return w >= 3;
@@ -226,8 +224,17 @@ public class WriteLoops {
226 224
         int w = 0;
227 225
         String adminPhoneNumber = "+1 202 456 1111";
228 226
 
227
+        while (serverIsRunning() == true) {
228
+            waitFor(5);
229
+            w = w + 1;
230
+        }
231
+
232
+        if(serverIsRunning() == false) {
233
+            sendEmergencyText("Help!", adminPhoneNumber);
234
+
235
+        }
229 236
         // calling
230
-        w = w + 1;
237
+
231 238
         // each time through the inner loop
232 239
 
233 240
         return w;
@@ -241,10 +248,10 @@ public class WriteLoops {
241 248
         int i = 0;
242 249
         // calling
243 250
         while(i<50) {
244
-        i+=7;
245
-        w = w + 1;
251
+            i+=7;
252
+            w = w + 1;
246 253
         }
247
-        
254
+
248 255
         // each time through the inner loop
249 256
 
250 257
         return w;
@@ -278,9 +285,13 @@ public class WriteLoops {
278 285
     public int rewriteFooAsFor() {
279 286
         int w = 0;
280 287
         int sumOfThrees = 0;
281
-
288
+        
289
+        for(int i = 0; i < threes_array.length; i++){
290
+            sumOfThrees += threes_array[i];
291
+            w = w + 1;
292
+        }
282 293
         // calling
283
-        w = w + 1;
294
+        
284 295
         // each time through the inner loop
285 296
 
286 297
         System.out.print("The Sum is ");
@@ -294,9 +305,15 @@ public class WriteLoops {
294 305
     public int rewriteFooAsWhile() {
295 306
         int w = 0;
296 307
         int sumOfThrees = 0;
297
-
308
+        int idx = 0;
309
+        
310
+        while(idx<threes_array.length) {
311
+            sumOfThrees += threes_array[idx];
312
+            idx++;
313
+            w = w + 1;
314
+        }
298 315
         // calling
299
-        w = w + 1;
316
+        
300 317
         // each time through the inner loop
301 318
 
302 319
         System.out.print("The Sum is ");
@@ -315,11 +332,18 @@ public class WriteLoops {
315 332
     public int manageYardAndJunior() {
316 333
         int w = 0;
317 334
         boolean onTime = true;
335
+        boolean yardNeedsMowed = true;
318 336
 
319 337
         // ADD YOUR CODE here.
338
+        while(isSummer()) {
339
+            if(yardNeedsMowed) {
340
+            yellAtJuniorToMowLawn();       
341
+            w = w + 1;
342
+            }
320 343
 
344
+        }
321 345
         // be sure to call
322
-        w = w + 1;
346
+        sendJuniorBackToSchool("First day of school");
323 347
         // each time inside the loop
324 348
 
325 349
         return w;
@@ -334,8 +358,11 @@ public class WriteLoops {
334 358
         int w = 0;
335 359
         int numberOfVotes = voteTallies.length;
336 360
 
337
-        // calling
338
-        w = w + 1;
361
+        for(int i = 0; i < numberOfVotes; i++) {
362
+            System.out.println(voteTallies[i]);
363
+            w = w + 1;
364
+        }// calling
365
+
339 366
         // each time through the inner loop
340 367
 
341 368
         return w;
@@ -346,10 +373,16 @@ public class WriteLoops {
346 373
     // where you are.
347 374
     public int tallyVote2() {
348 375
         int w = 0;
376
+        int idx = 0;
349 377
         int numberOfVotes = voteTallies.length;
350 378
 
379
+        while(idx < numberOfVotes) {
380
+            System.out.println(voteTallies[idx]);
381
+            idx++;
382
+            w = w + 1;
383
+        }
351 384
         // calling
352
-        w = w + 1;
385
+
353 386
         // each time through the inner loop
354 387
 
355 388
         return w;

+ 40
- 0
WriteLoopsTest.java ファイルの表示

@@ -124,6 +124,41 @@ public class WriteLoopsTest
124 124
         WriteLoops writeLoo1 = new WriteLoops();
125 125
         assertEquals(3, writeLoo1.checkServerStatus());
126 126
     }
127
+
128
+    @Test
129
+    public void loop50by7()
130
+    {
131
+        WriteLoops writeLoo1 = new WriteLoops();
132
+        assertEquals(8, writeLoo1.loop50by7());
133
+    }
134
+
135
+    @Test
136
+    public void tallyVoteTest1()
137
+    {
138
+        WriteLoops writeLoo1 = new WriteLoops();
139
+        assertEquals(13, writeLoo1.tallyVote1());
140
+    }
141
+
142
+    @Test
143
+    public void tallyVoteTest2()
144
+    {
145
+        WriteLoops writeLoo1 = new WriteLoops();
146
+        assertEquals(13, writeLoo1.tallyVote2());
147
+    }
148
+
149
+    @Test
150
+    public void rewriteFooForTest()
151
+    {
152
+        WriteLoops writeLoo2 = new WriteLoops();
153
+        assertEquals(7, writeLoo2.rewriteFooAsFor());
154
+    }
155
+
156
+    @Test
157
+    public void rewriteFooWhileTest()
158
+    {
159
+        WriteLoops writeLoo1 = new WriteLoops();
160
+        assertEquals(7, writeLoo1.rewriteFooAsWhile());
161
+    }
127 162
 }
128 163
 
129 164
 
@@ -136,3 +171,8 @@ public class WriteLoopsTest
136 171
 
137 172
 
138 173
 
174
+
175
+
176
+
177
+
178
+