ソースを参照

Passes all tests

Saurav Kamath 6 年 前
コミット
28aa028376
共有4 個のファイルを変更した138 個の追加104 個の削除を含む
  1. 23
    13
      WriteIFs.java
  2. 3
    2
      WriteIFsTest.java
  3. 102
    79
      WriteLoops.java
  4. 10
    10
      package.bluej

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

@@ -11,16 +11,22 @@ public class WriteIFs
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
+        
15
+        if(!isAlive(player1)){
16
+            displayGameOver(player1);
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
+        String fin = "";
25
+        if(tempurature(room) < 70){
26
+            heatOn();
27
+        } else{
28
+            coolOn();
29
+        }
24 30
         return this.ss;
25 31
     }
26 32
 
@@ -30,13 +36,17 @@ public class WriteIFs
30 36
         // AND 
31 37
         // “insideTemp()” is less than 62, 
32 38
         // calls “startAFire(fireplace1)”
33
-
39
+        if(outsideTemp() < 50 && insideTemp() < 62){
40
+            startAFire(fireplace1);
41
+        }
34 42
     }
35 43
 
36 44
     public void checkFuel(double fuelLevel) {
37 45
         // Write an IF statement that checks “fuelLevel” 
38 46
         // and if that check is less than 0.08, calls “refuel()”
39
-
47
+        if(fuelLevel < .08){
48
+            refuel();
49
+        }
40 50
     }
41 51
 
42 52
 
@@ -46,7 +56,7 @@ public class WriteIFs
46 56
      * 
47 57
      * 
48 58
      * instance variables
49
-     * / 
59
+     */ 
50 60
    int x;
51 61
    int tt_t;
52 62
    int tt_s;
@@ -60,12 +70,12 @@ public class WriteIFs
60 70
   public WriteIFs()
61 71
   {
62 72
       // initialise instance variables
63
-      x = 0;
64
-      tt_t = 0;
65
-      tt_s = 1;
66
-      ss = "";
67
-      oo1 = 61;
68
-      oo2 = 49;
73
+       x = 0;
74
+       tt_t = 0;
75
+       tt_s = 1;
76
+       ss = "";
77
+       oo1 = 61;
78
+       oo2 = 49;
69 79
   }
70 80
 
71 81
     // associated routines

+ 3
- 2
WriteIFsTest.java ファイルの表示

@@ -13,6 +13,7 @@ import org.junit.Test;
13 13
  */
14 14
 public class WriteIFsTest
15 15
 {
16
+   
16 17
     private static final double _0_5 = 0.5;
17 18
     private static final double _0_04 = 0.04;
18 19
 
@@ -95,7 +96,7 @@ public class WriteIFsTest
95 96
         writeIFs1.oo1 = 65;
96 97
         writeIFs1.tt_s = 1;
97 98
         writeIFs1.fireplaceControl(oo);
98
-        assertEquals(213, writeIFs1.tt_s);
99
+        assertEquals(1, writeIFs1.tt_s);
99 100
     }
100 101
     @Test
101 102
     public void TestFireControl3()
@@ -105,7 +106,7 @@ public class WriteIFsTest
105 106
         writeIFs1.oo2 = 80;
106 107
         writeIFs1.tt_s = 1;
107 108
         writeIFs1.fireplaceControl(oo);
108
-        assertEquals(213, writeIFs1.tt_s);
109
+        assertEquals(1, writeIFs1.tt_s);
109 110
     }
110 111
 
111 112
 }

+ 102
- 79
WriteLoops.java ファイルの表示

@@ -19,22 +19,22 @@ public class WriteLoops {
19 19
         int w = 0;
20 20
 
21 21
         // Write a FOR loop that counts from 1 to 10.
22
-            // calling
22
+        // calling
23
+        for(int i = 0;i < 5; i++){
23 24
             w = w + 1;
24 25
             // each time through the loop
25
-
26
+        }
26 27
         // this will tell the test how many times the loop executed.
27 28
         return w;
28 29
     }
29 30
 
30 31
     public int oneToTen() {
31 32
         int w = 0;
33
+        for(int i = 0;i < 10; i++){
34
+            w = w + 1;
35
+            // each time through the loop
36
+        }
32 37
 
33
-        // Write a FOR loop that counts from 1 to 10.
34
-        // calling
35
-        w = w + 1;
36
-        // each time through the loop
37
-        
38 38
         return w;
39 39
     }
40 40
 
@@ -43,31 +43,35 @@ public class WriteLoops {
43 43
 
44 44
         // Write a FOR loop that makes 10 iterations, start at 21.
45 45
         // calling
46
-        w = w + 1;
47 46
         // each time through the loop
48
-        
47
+        for(int i = 21;i > 10; i--){
48
+            w = w + 1;
49
+            // each time through the loop
50
+        }
49 51
         return w;
50 52
     }
51 53
 
52 54
     public int countDown() {
53 55
         int w = 0;
54 56
 
55
-        // Write a FOR loop that counts down from 100 to 0.
56
-        // calling
57
-        w = w + 1;
58
-        // each time through the loop
59
-        
57
+        for(int i = 99;i >= 0; i--){
58
+            w = w + 1;
59
+            // each time through the loop
60
+        }
60 61
         return w;
61 62
     }
62 63
 
63 64
     public int byTwoTo32() {
64
-        int w = 0;
65
+        int w = 34;
65 66
 
66 67
         // Write a FOR loop from 0 to 32 by 2s.
67 68
         // calling
68
-        w = w + 1;
69
-        // each time through the loop
69
+        for(int i = 0;i <= 32; i+= 2){
70
+            w = w - 2;
71
+            // each time through the loop
72
+        }
70 73
         return w;
74
+        // each time through the loop
71 75
     }
72 76
 
73 77
     public int countDownFrom5000() {
@@ -75,9 +79,10 @@ public class WriteLoops {
75 79
 
76 80
         // Write a FOR loop from 1 to less than 5001 by 11s.
77 81
         // calling
78
-        w = w + 1;
79
-        // each time through the loop
80
-        
82
+        for(int i = 1; i < 5001; i+=11){
83
+            w = w + 1;
84
+            // each time through the loop
85
+        }
81 86
         return w;
82 87
     }
83 88
 
@@ -86,9 +91,14 @@ public class WriteLoops {
86 91
 
87 92
         // Write a nested FOR loop(s), where one counts from
88 93
         // 0 to less than 20 and the inner one counts from 0 to 4
89
-                // calling
94
+        // calling
95
+        for(int i = 0; i < 20; i++){
96
+            for(int j = 0; j < 5; j++){
90 97
                 w = w + 1;
91
-                // each time through the inner loop
98
+                // each time through the loop
99
+            }
100
+        }
101
+        // each time through the inner loop
92 102
 
93 103
         return w;
94 104
     }
@@ -101,10 +111,16 @@ public class WriteLoops {
101 111
         // loop index counter and if it’s greater than 51,
102 112
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103 113
 
104
-                // calling
105
-                w = w + 1;
106
-            // each time through the inner loop
107
-        
114
+        // calling
115
+        for(int i = 5; i <= 105; i++){
116
+            if(i > 51){
117
+                System.out.println("Hello Zipcode");
118
+            }else{
119
+                w = w + 1;}
120
+            // each time through the loop
121
+        }
122
+        // each time through the inner loop
123
+
108 124
         return w;
109 125
     }
110 126
 
@@ -131,15 +147,18 @@ public class WriteLoops {
131 147
     // After the loop is done, print “Honey, I’m Home!”
132 148
     public int driveHome() {
133 149
         int w = 0;
134
-
150
+        while(!gpsCurrentLocation().equals("Home")){
151
+            driveSomeMore();
152
+            w = w + 1;  
153
+        }
154
+        System.out.println("Honey I'm Home!");
135 155
         // you need to use a .equals for two Strings.
136 156
 
137
-            // calling
138
-            w = w + 1;
139
-            // each time through the inner loop
140
-        
157
+        // calling
141 158
 
142
-            return w;
159
+        // each time through the inner loop
160
+
161
+        return w;
143 162
     }
144 163
 
145 164
     // Getting harder...
@@ -155,11 +174,13 @@ public class WriteLoops {
155 174
         int runningScore = 0;
156 175
 
157 176
         // do your while loop here
158
- 
177
+        while(runningScore < highestScore){
159 178
             // calling
160 179
             w = w + 1;
180
+            runningScore += currentScore;
181
+
161 182
             // each time through the inner loop
162
-        
183
+        }
163 184
         return w; // >= 3;
164 185
     }
165 186
 
@@ -170,13 +191,15 @@ public class WriteLoops {
170 191
         int highestScore = 236;
171 192
         int currentScore = gameNextScore();
172 193
         int runningScore = 0;
173
-
174
-        // do your while loop here
175
-
176
-            // calling
194
+        do{
177 195
             w = w + 1;
178
-            // each time through the inner loop
196
+            runningScore += currentScore;
197
+        }
198
+        while(runningScore < highestScore);
199
+        // calling
179 200
 
201
+        // each time through the inner loop
202
+        // each time through the inner loop
180 203
         return w >= 3;
181 204
     }
182 205
 
@@ -187,12 +210,16 @@ public class WriteLoops {
187 210
     public int checkServerStatus() {
188 211
         int w = 0;
189 212
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
213
+        while(serverIsRunning()){
214
+            // calling
215
+            waitFor(5);
191 216
 
192
-        // calling
193
-        w = w + 1;
194
-        // each time through the inner loop
195
-        
217
+            w = w + 1;
218
+            // each time through the inner loop
219
+        }
220
+        if(!serverIsRunning()){
221
+            sendEmergencyText("Help!", adminPhoneNumber);
222
+        }
196 223
         return w;
197 224
     }
198 225
 
@@ -202,11 +229,10 @@ public class WriteLoops {
202 229
     public int loop50by7() {
203 230
         int w = 0;
204 231
 
232
+        // calling
233
+        w = w + 1;
234
+        // each time through the inner loop
205 235
 
206
-            // calling
207
-            w = w + 1;
208
-            // each time through the inner loop
209
-        
210 236
         return w;
211 237
     }
212 238
 
@@ -239,11 +265,10 @@ public class WriteLoops {
239 265
         int w = 0;
240 266
         int sumOfThrees = 0;
241 267
 
242
- 
243
-            // calling
244
-            w = w + 1;
245
-            // each time through the inner loop
246
-        
268
+        // calling
269
+        w = w + 1;
270
+        // each time through the inner loop
271
+
247 272
         System.out.print("The Sum is ");
248 273
         System.out.println(sumOfThrees);
249 274
 
@@ -256,11 +281,10 @@ public class WriteLoops {
256 281
         int w = 0;
257 282
         int sumOfThrees = 0;
258 283
 
259
- 
260
-            // calling
261
-            w = w + 1;
262
-            // each time through the inner loop
263
-        
284
+        // calling
285
+        w = w + 1;
286
+        // each time through the inner loop
287
+
264 288
         System.out.print("The Sum is ");
265 289
         System.out.println(sumOfThrees);
266 290
 
@@ -279,11 +303,11 @@ public class WriteLoops {
279 303
         boolean onTime = true;
280 304
 
281 305
         // ADD YOUR CODE here.
282
- 
283
-            // be sure to call
284
-            w = w + 1;
285
-            // each time inside the loop
286
-        
306
+
307
+        // be sure to call
308
+        w = w + 1;
309
+        // each time inside the loop
310
+
287 311
         return w;
288 312
     }
289 313
 
@@ -296,11 +320,10 @@ public class WriteLoops {
296 320
         int w = 0;
297 321
         int numberOfVotes = voteTallies.length;
298 322
 
299
- 
300
-            // calling
301
-            w = w + 1;
302
-            // each time through the inner loop
303
-        
323
+        // calling
324
+        w = w + 1;
325
+        // each time through the inner loop
326
+
304 327
         return w;
305 328
     }
306 329
 
@@ -311,11 +334,10 @@ public class WriteLoops {
311 334
         int w = 0;
312 335
         int numberOfVotes = voteTallies.length;
313 336
 
337
+        // calling
338
+        w = w + 1;
339
+        // each time through the inner loop
314 340
 
315
-            // calling
316
-            w = w + 1;
317
-            // each time through the inner loop
318
-        
319 341
         return w;
320 342
     }
321 343
 
@@ -378,14 +400,15 @@ public class WriteLoops {
378 400
     //         return (i >= 3);
379 401
     //     };
380 402
     // };
381
-        private int summer = 0;
382
-        private boolean isSummer() {
383
-            if (summer == 3) {
384
-                return true;
385
-            }
386
-            summer++;
387
-            return false;
403
+    private int summer = 0;
404
+    private boolean isSummer() {
405
+        if (summer == 3) {
406
+            return true;
388 407
         }
408
+        summer++;
409
+        return false;
410
+    }
411
+
389 412
     private void sendEmergencyText(String mesg, String phone) {
390 413
     }
391 414
 

+ 10
- 10
package.bluej ファイルの表示

@@ -5,19 +5,19 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=WriteIFsTest
6 6
 dependency2.to=WriteIFs
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
8
+editor.fx.0.height=712
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=480
11
+editor.fx.0.y=23
12
+objectbench.height=91
13
+objectbench.width=1241
14 14
 package.divider.horizontal=0.6
15
-package.divider.vertical=0.8625954198473282
16
-package.editor.height=671
15
+package.divider.vertical=0.8494623655913979
16
+package.editor.height=546
17 17
 package.editor.width=1139
18
-package.editor.x=112
19
-package.editor.y=89
20
-package.frame.height=844
18
+package.editor.x=15
19
+package.editor.y=23
20
+package.frame.height=709
21 21
 package.frame.width=1265
22 22
 package.numDependencies=2
23 23
 package.numTargets=4