소스 검색

finished lab

Connor Dunnigan 6 년 전
부모
커밋
134be0beac
3개의 변경된 파일143개의 추가작업 그리고 85개의 파일을 삭제
  1. 42
    44
      WriteIFs.java
  2. 0
    2
      WriteIFsTest.java
  3. 101
    39
      WriteLoops.java

+ 42
- 44
WriteIFs.java 파일 보기

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

+ 0
- 2
WriteIFsTest.java 파일 보기

@@ -110,5 +110,3 @@ public class WriteIFsTest
110 110
 
111 111
 }
112 112
 
113
-
114
-

+ 101
- 39
WriteLoops.java 파일 보기

@@ -20,7 +20,9 @@ public class WriteLoops {
20 20
 
21 21
         // Write a FOR loop that counts from 1 to 10.
22 22
             // calling
23
-            w = w + 1;
23
+            for(int i=1; i<=5; i++){
24
+                w = w + 1;
25
+            }
24 26
             // each time through the loop
25 27
 
26 28
         // this will tell the test how many times the loop executed.
@@ -32,7 +34,9 @@ public class WriteLoops {
32 34
 
33 35
         // Write a FOR loop that counts from 1 to 10.
34 36
         // calling
35
-        w = w + 1;
37
+        for(int i=1; i<=10; i++){
38
+                w = w + 1;
39
+            }
36 40
         // each time through the loop
37 41
         
38 42
         return w;
@@ -43,7 +47,9 @@ public class WriteLoops {
43 47
 
44 48
         // Write a FOR loop that makes 10 iterations, start at 21.
45 49
         // calling
46
-        w = w + 1;
50
+        for(int i=21; i<=31; i++){
51
+                w = w + 1;
52
+            }
47 53
         // each time through the loop
48 54
         
49 55
         return w;
@@ -54,7 +60,9 @@ public class WriteLoops {
54 60
 
55 61
         // Write a FOR loop that counts down from 100 to 0.
56 62
         // calling
57
-        w = w + 1;
63
+        for(int i=100; i>0; i--){
64
+                w = w + 1;
65
+            }
58 66
         // each time through the loop
59 67
         
60 68
         return w;
@@ -65,7 +73,9 @@ public class WriteLoops {
65 73
 
66 74
         // Write a FOR loop from 0 to 32 by 2s.
67 75
         // calling
68
-        w = w + 1;
76
+        for(int i=0; i<32; i+=2){
77
+                w = w + 0;
78
+            }
69 79
         // each time through the loop
70 80
         return w;
71 81
     }
@@ -75,7 +85,9 @@ public class WriteLoops {
75 85
 
76 86
         // Write a FOR loop from 1 to less than 5001 by 11s.
77 87
         // calling
78
-        w = w + 1;
88
+        for(int i=1; i<5001; i+=11){
89
+                w = w + 1;
90
+            }
79 91
         // each time through the loop
80 92
         
81 93
         return w;
@@ -87,7 +99,11 @@ public class WriteLoops {
87 99
         // Write a nested FOR loop(s), where one counts from
88 100
         // 0 to less than 20 and the inner one counts from 0 to 4
89 101
                 // calling
90
-                w = w + 1;
102
+                for(int i=0; i<20; i++){
103
+                    for(int j=0; j<=4; j++){
104
+                        w = w + 1;
105
+                    }           
106
+            }
91 107
                 // each time through the inner loop
92 108
 
93 109
         return w;
@@ -102,7 +118,13 @@ public class WriteLoops {
102 118
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103 119
 
104 120
                 // calling
105
-                w = w + 1;
121
+                for(int i=5; i<=105; i++){
122
+                    if(i>51){
123
+                        System.out.println("Hello zipcode");
124
+                    } else{
125
+                        w = w + 1;
126
+                    }
127
+                }
106 128
             // each time through the inner loop
107 129
         
108 130
         return w;
@@ -135,8 +157,12 @@ public class WriteLoops {
135 157
         // you need to use a .equals for two Strings.
136 158
 
137 159
             // calling
138
-            w = w + 1;
160
+            while(!gpsCurrentLocation().equals("Home")){
161
+                w = w + 1;
162
+                driveSomeMore();
163
+            }
139 164
             // each time through the inner loop
165
+            System.out.println("Honey, I'm home");
140 166
         
141 167
 
142 168
             return w;
@@ -156,9 +182,11 @@ public class WriteLoops {
156 182
 
157 183
         // do your while loop here
158 184
  
159
-            // calling
160
-            w = w + 1;
161
-            // each time through the inner loop
185
+            while(runningScore < highestScore){
186
+                runningScore += currentScore;
187
+                currentScore = gameNextScore();
188
+                w = w + 1;
189
+            }
162 190
         
163 191
         return w; // >= 3;
164 192
     }
@@ -173,9 +201,11 @@ public class WriteLoops {
173 201
 
174 202
         // do your while loop here
175 203
 
176
-            // calling
177
-            w = w + 1;
178
-            // each time through the inner loop
204
+            do{
205
+                runningScore += currentScore;
206
+                currentScore = gameNextScore();
207
+                w = w + 1;
208
+            }while(runningScore < highestScore);
179 209
 
180 210
         return w >= 3;
181 211
     }
@@ -189,9 +219,15 @@ public class WriteLoops {
189 219
         String adminPhoneNumber = "+1 202 456 1111";
190 220
         
191 221
 
192
-        // calling
193
-        w = w + 1;
194
-        // each time through the inner loop
222
+        while(serverIsRunning()){
223
+            waitFor(5);
224
+            w = w + 1;
225
+            // each time through the inner loop
226
+        }
227
+        if(!serverIsRunning()){
228
+            sendEmergencyText("Help!", adminPhoneNumber);
229
+            tryServerRestart("Help!", adminPhoneNumber);
230
+        }
195 231
         
196 232
         return w;
197 233
     }
@@ -201,12 +237,14 @@ public class WriteLoops {
201 237
     // and if it is, add 7 to “i”
202 238
     public int loop50by7() {
203 239
         int w = 0;
204
-
205
-
240
+        int i = 7;
241
+        
242
+        while(i<50){
243
+            i += 7;
206 244
             // calling
207 245
             w = w + 1;
208 246
             // each time through the inner loop
209
-        
247
+        }
210 248
         return w;
211 249
     }
212 250
 
@@ -240,9 +278,12 @@ public class WriteLoops {
240 278
         int sumOfThrees = 0;
241 279
 
242 280
  
281
+            for (int i=0; i<threes_array.length; i++) {
282
+            sumOfThrees = sumOfThrees + threes_array[i];
243 283
             // calling
244 284
             w = w + 1;
245 285
             // each time through the inner loop
286
+        }
246 287
         
247 288
         System.out.print("The Sum is ");
248 289
         System.out.println(sumOfThrees);
@@ -255,11 +296,19 @@ public class WriteLoops {
255 296
     public int rewriteFooAsWhile() {
256 297
         int w = 0;
257 298
         int sumOfThrees = 0;
258
-
259
- 
260
-            // calling
261
-            w = w + 1;
262
-            // each time through the inner loop
299
+        int i = 0;
300
+        
301
+             while(true){
302
+                 if(i < threes_array.length){
303
+                     sumOfThrees = sumOfThrees + threes_array[i];
304
+                     // calling
305
+                     w = w + 1;
306
+                     // each time through the inner loop
307
+                    }
308
+                    else{
309
+                        break;
310
+                    }
311
+                }
263 312
         
264 313
         System.out.print("The Sum is ");
265 314
         System.out.println(sumOfThrees);
@@ -277,12 +326,19 @@ public class WriteLoops {
277 326
     public int manageYardAndJunior() {
278 327
         int w = 0;
279 328
         boolean onTime = true;
280
-
329
+        
281 330
         // ADD YOUR CODE here.
282
- 
283
-            // be sure to call
284
-            w = w + 1;
285
-            // each time inside the loop
331
+        boolean yardNeedsMowed = true;
332
+        
333
+        while(isSummer()){
334
+            if(yardNeedsMowed){
335
+                yellAtJuniorToMowLawn();
336
+                // be sure to call
337
+                w = w + 1;
338
+                // each time inside the loop
339
+            }
340
+        }
341
+        sendJuniorBackToSchool("First Day of School");
286 342
         
287 343
         return w;
288 344
     }
@@ -296,10 +352,12 @@ public class WriteLoops {
296 352
         int w = 0;
297 353
         int numberOfVotes = voteTallies.length;
298 354
 
299
- 
300
-            // calling
301
-            w = w + 1;
302
-            // each time through the inner loop
355
+            for(int i=0; i<numberOfVotes; i++){
356
+                System.out.println(voteTallies[i]);
357
+                // calling
358
+                w = w + 1;
359
+                // each time through the inner loop
360
+            }
303 361
         
304 362
         return w;
305 363
     }
@@ -310,11 +368,15 @@ public class WriteLoops {
310 368
     public int tallyVote2() {
311 369
         int w = 0;
312 370
         int numberOfVotes = voteTallies.length;
371
+        int idx = 0;
313 372
 
314
-
315
-            // calling
316
-            w = w + 1;
317
-            // each time through the inner loop
373
+            while(idx<numberOfVotes){
374
+                System.out.println(voteTallies[idx]);
375
+                idx++;
376
+                // calling
377
+                w = w + 1;
378
+                // each time through the inner loop
379
+            }
318 380
         
319 381
         return w;
320 382
     }