Selaa lähdekoodia

Completed Saturday

De'Jon Johnson 6 vuotta sitten
vanhempi
commit
7269ccf738
5 muutettua tiedostoa jossa 184 lisäystä ja 122 poistoa
  1. 29
    9
      WriteIFs.java
  2. 6
    0
      WriteIFsTest.java
  3. 134
    98
      WriteLoops.java
  4. 1
    1
      WriteLoopsTest.java
  5. 14
    14
      package.bluej

+ 29
- 9
WriteIFs.java Näytä tiedosto

@@ -8,20 +8,33 @@
8 8
 public class WriteIFs
9 9
 {
10 10
  
11
+   int x;
12
+   int tt_t;
13
+   int tt_s;
14
+   int oo1, oo2;
15
+   String ss;
16
+   
11 17
     public void playerDied(boolean player1) {
12 18
         // Write an IF statement that checks “player1.isAlive()” 
13 19
         // and if that’s false, calls “displayGameOver(player1)”
14
-     
20
+        
21
+        if(isAlive(true)){
22
+            
23
+    } else{
24
+        displayGameOver(player1);
15 25
     }
16 26
     
27
+}
17 28
     public String thermoSTAT(int room) {
18 29
         // Write an IF statement that checks the 
19 30
         // “temperature(room)” and if that check is less than 70, 
20 31
         // calls “heatOn()” else calls “coolOn()”
21
-
22
-
23
-        
24
-        return this.ss;
32
+              if(temperature(room) <= 70){
33
+                  heatOn();
34
+                } else{
35
+                    coolOn();
36
+                }
37
+                return this.ss;
25 38
     }
26 39
 
27 40
     public void fireplaceControl(Object fireplace1) {
@@ -30,14 +43,21 @@ public class WriteIFs
30 43
         // AND 
31 44
         // “insideTemp()” is less than 62, 
32 45
         // calls “startAFire(fireplace1)”
33
-
34
-    }
46
+        
47
+        if(outsideTemp() <50 || insideTemp() <62){
48
+            startAFire(fireplace1);
49
+            
50
+    } 
51
+}
35 52
 
36 53
     public void checkFuel(double fuelLevel) {
37 54
         // Write an IF statement that checks “fuelLevel” 
38 55
         // and if that check is less than 0.08, calls “refuel()”
39
-
56
+        
57
+        if(fuelLevel < 0.08){
58
+            refuel();
40 59
     }
60
+}
41 61
 
42 62
 
43 63
     
@@ -72,7 +92,7 @@ public class WriteIFs
72 92
     public boolean isAlive(boolean p) {
73 93
         return !p;
74 94
     }
75
-    private int tempurature(int t) {
95
+    private int temperature(int t) {
76 96
         return t+2;
77 97
     }
78 98
     private void heatOn() {

+ 6
- 0
WriteIFsTest.java Näytä tiedosto

@@ -13,6 +13,12 @@ import org.junit.Test;
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
 

+ 134
- 98
WriteLoops.java Näytä tiedosto

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

+ 1
- 1
WriteLoopsTest.java Näytä tiedosto

@@ -71,7 +71,7 @@ public class WriteLoopsTest
71 71
     public void Test2to32()
72 72
     {
73 73
         WriteLoops writeLoo1 = new WriteLoops();
74
-        assertEquals(0, writeLoo1.byTwoTo32());
74
+        assertEquals(16, writeLoo1.byTwoTo32());
75 75
     }
76 76
 
77 77
     @Test

+ 14
- 14
package.bluej Näytä tiedosto

@@ -1,23 +1,23 @@
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
-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=804
9
+editor.fx.0.width=1068
10
+editor.fx.0.x=372
11
+editor.fx.0.y=23
12
+objectbench.height=108
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.847682119205298
16
+package.editor.height=633
17 17
 package.editor.width=1139
18 18
 package.editor.x=112
19
-package.editor.y=89
20
-package.frame.height=844
19
+package.editor.y=23
20
+package.frame.height=813
21 21
 package.frame.width=1265
22 22
 package.numDependencies=2
23 23
 package.numTargets=4