瀏覽代碼

finished first saturday lab

Jonathan Hinds 8 年之前
父節點
當前提交
63cfa4b662
共有 3 個文件被更改,包括 172 次插入109 次删除
  1. 32
    13
      WriteIFs.java
  2. 126
    82
      WriteLoops.java
  3. 14
    14
      package.bluej

+ 32
- 13
WriteIFs.java 查看文件

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

+ 126
- 82
WriteLoops.java 查看文件

@@ -1,5 +1,4 @@
1 1
 import com.sun.org.apache.xpath.internal.SourceTree;
2
-
3 2
 import java.awt.SystemTray;
4 3
 import java.util.concurrent.ThreadLocalRandom;
5 4
 import java.util.function.Supplier;
@@ -19,11 +18,16 @@ public class WriteLoops {
19 18
         int w = 0;
20 19
 
21 20
         // Write a FOR loop that counts from 1 to 10.
22
-            // calling
23
-            w = w + 1;
24
-            // each time through the loop
21
+        // calling
22
+        w = w + 1;
23
+        // each time through the loop
25 24
 
26 25
         // this will tell the test how many times the loop executed.
26
+
27
+        for (int i = 1; i < 5; i ++)
28
+        {
29
+            w = w+1;
30
+        }
27 31
         return w;
28 32
     }
29 33
 
@@ -34,7 +38,11 @@ public class WriteLoops {
34 38
         // calling
35 39
         w = w + 1;
36 40
         // each time through the loop
37
-        
41
+
42
+        for(int i = 1; i < 10; i ++){
43
+            w = w + 1;
44
+        }
45
+
38 46
         return w;
39 47
     }
40 48
 
@@ -43,9 +51,12 @@ public class WriteLoops {
43 51
 
44 52
         // Write a FOR loop that makes 10 iterations, start at 21.
45 53
         // calling
46
-        w = w + 1;
54
+        for(int i = 21; i < 32; i ++)
55
+        {
56
+            w = w + 1;
57
+        }
47 58
         // each time through the loop
48
-        
59
+
49 60
         return w;
50 61
     }
51 62
 
@@ -54,30 +65,29 @@ public class WriteLoops {
54 65
 
55 66
         // Write a FOR loop that counts down from 100 to 0.
56 67
         // calling
57
-        w = w + 1;
58
-        // each time through the loop
59
-        
68
+        for(int i = 0; i < 100; i ++){
69
+            w = w + 1;
70
+            // each time through the loop
71
+        }
60 72
         return w;
61 73
     }
62 74
 
63 75
     public int byTwoTo32() {
64 76
         int w = 0;
65
-
66
-        // Write a FOR loop from 0 to 32 by 2s.
67
-        // calling
68
-        w = w + 1;
69
-        // each time through the loop
77
+        for(int i = 0; i < 32; i += 2)
78
+        {
79
+            //w = w + 1;
80
+        }
70 81
         return w;
71 82
     }
72 83
 
73 84
     public int countDownFrom5000() {
74 85
         int w = 0;
86
+        for(int i = 1; i < 5001; i += 11)
87
+        {
88
+            w = w + 1;
89
+        }
75 90
 
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 91
         return w;
82 92
     }
83 93
 
@@ -86,10 +96,17 @@ public class WriteLoops {
86 96
 
87 97
         // Write a nested FOR loop(s), where one counts from
88 98
         // 0 to less than 20 and the inner one counts from 0 to 4
89
-                // calling
90
-                w = w + 1;
91
-                // each time through the inner loop
99
+        // calling
100
+        //w = w + 1;
101
+        // each time through the inner loop
92 102
 
103
+        for(int i = 0; i < 20; i ++)
104
+        {
105
+            for(int j = 0; j <= 4; j ++)
106
+            {
107
+                w = w + 1; 
108
+            }
109
+        }
93 110
         return w;
94 111
     }
95 112
 
@@ -101,10 +118,20 @@ public class WriteLoops {
101 118
         // loop index counter and if it’s greater than 51,
102 119
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103 120
 
104
-                // calling
121
+        // calling
122
+
123
+        // each time through the inner loop
124
+
125
+        for(int i = 5; i < 105; i ++)
126
+        {
127
+            if(i > 51)
128
+            {
129
+                System.out.println("Hello Zipcode");
130
+            } else {
105 131
                 w = w + 1;
106
-            // each time through the inner loop
107
-        
132
+            }
133
+        }
134
+
108 135
         return w;
109 136
     }
110 137
 
@@ -133,13 +160,16 @@ public class WriteLoops {
133 160
         int w = 0;
134 161
 
135 162
         // you need to use a .equals for two Strings.
136
-
163
+        while(!gpsCurrentLocation().equals("Home"))
164
+        {
137 165
             // calling
138 166
             w = w + 1;
139 167
             // each time through the inner loop
140
-        
168
+            driveSomeMore();
141 169
 
142
-            return w;
170
+        }
171
+        System.out.println("Honey, I'm Home!");
172
+        return w;
143 173
     }
144 174
 
145 175
     // Getting harder...
@@ -149,17 +179,21 @@ public class WriteLoops {
149 179
     // "runningScore"
150 180
     // and then sets “currentScore” to “gameNextScore()”
151 181
     public int checkGameScore() {
152
-        int w = 0;
153
-        int highestScore = 236;
154
-        int currentScore = gameNextScore();
155
-        int runningScore = 0;
182
+    int w = 0;
183
+    int highestScore = 236;
184
+    int currentScore = gameNextScore();
185
+    int runningScore = 0;
156 186
 
157 187
         // do your while loop here
158
- 
159
-            // calling
188
+    while(runningScore < highestScore){
189
+        if(runningScore < highestScore)
190
+        {
191
+            runningScore += currentScore;
160 192
             w = w + 1;
161
-            // each time through the inner loop
193
+        }
194
+        currentScore = gameNextScore();
162 195
         
196
+    }
163 197
         return w; // >= 3;
164 198
     }
165 199
 
@@ -171,12 +205,14 @@ public class WriteLoops {
171 205
         int currentScore = gameNextScore();
172 206
         int runningScore = 0;
173 207
 
174
-        // do your while loop here
175
-
176
-            // calling
177
-            w = w + 1;
178
-            // each time through the inner loop
179
-
208
+        do {
209
+            if(runningScore < highestScore)
210
+            {
211
+                runningScore += currentScore;
212
+                w = w + 1;
213
+            }
214
+            currentScore = gameNextScore();
215
+        }while(runningScore < highestScore);
180 216
         return w >= 3;
181 217
     }
182 218
 
@@ -187,12 +223,19 @@ public class WriteLoops {
187 223
     public int checkServerStatus() {
188 224
         int w = 0;
189 225
         String adminPhoneNumber = "+1 202 456 1111";
226
+        while(serverIsRunning())
227
+        {
228
+            if(serverIsRunning() == true)
229
+            {
230
+                waitFor(5);
231
+            }
232
+            w = w + 1;
233
+        }
190 234
         
191
-
192
-        // calling
193
-        w = w + 1;
194
-        // each time through the inner loop
195
-        
235
+        if(serverIsRunning() == false){
236
+            sendEmergencyText("Help", adminPhoneNumber);
237
+            tryServerRestart("Help", adminPhoneNumber);
238
+        }
196 239
         return w;
197 240
     }
198 241
 
@@ -201,12 +244,16 @@ public class WriteLoops {
201 244
     // and if it is, add 7 to “i”
202 245
     public int loop50by7() {
203 246
         int w = 0;
204
-
205
-
206
-            // calling
247
+        int i = 7;
248
+        while(i < 50){
249
+            i += 7;
207 250
             w = w + 1;
208
-            // each time through the inner loop
251
+        }
252
+
253
+        // calling
209 254
         
255
+        // each time through the inner loop
256
+
210 257
         return w;
211 258
     }
212 259
 
@@ -239,11 +286,10 @@ public class WriteLoops {
239 286
         int w = 0;
240 287
         int sumOfThrees = 0;
241 288
 
242
- 
243
-            // calling
244
-            w = w + 1;
245
-            // each time through the inner loop
246
-        
289
+        // calling
290
+        w = w + 1;
291
+        // each time through the inner loop
292
+
247 293
         System.out.print("The Sum is ");
248 294
         System.out.println(sumOfThrees);
249 295
 
@@ -256,11 +302,10 @@ public class WriteLoops {
256 302
         int w = 0;
257 303
         int sumOfThrees = 0;
258 304
 
259
- 
260
-            // calling
261
-            w = w + 1;
262
-            // each time through the inner loop
263
-        
305
+        // calling
306
+        w = w + 1;
307
+        // each time through the inner loop
308
+
264 309
         System.out.print("The Sum is ");
265 310
         System.out.println(sumOfThrees);
266 311
 
@@ -279,11 +324,11 @@ public class WriteLoops {
279 324
         boolean onTime = true;
280 325
 
281 326
         // ADD YOUR CODE here.
282
- 
283
-            // be sure to call
284
-            w = w + 1;
285
-            // each time inside the loop
286
-        
327
+
328
+        // be sure to call
329
+        w = w + 1;
330
+        // each time inside the loop
331
+
287 332
         return w;
288 333
     }
289 334
 
@@ -296,11 +341,10 @@ public class WriteLoops {
296 341
         int w = 0;
297 342
         int numberOfVotes = voteTallies.length;
298 343
 
299
- 
300
-            // calling
301
-            w = w + 1;
302
-            // each time through the inner loop
303
-        
344
+        // calling
345
+        w = w + 1;
346
+        // each time through the inner loop
347
+
304 348
         return w;
305 349
     }
306 350
 
@@ -311,11 +355,10 @@ public class WriteLoops {
311 355
         int w = 0;
312 356
         int numberOfVotes = voteTallies.length;
313 357
 
358
+        // calling
359
+        w = w + 1;
360
+        // each time through the inner loop
314 361
 
315
-            // calling
316
-            w = w + 1;
317
-            // each time through the inner loop
318
-        
319 362
         return w;
320 363
     }
321 364
 
@@ -378,14 +421,15 @@ public class WriteLoops {
378 421
     //         return (i >= 3);
379 422
     //     };
380 423
     // };
381
-        private int summer = 0;
382
-        private boolean isSummer() {
383
-            if (summer == 3) {
384
-                return true;
385
-            }
386
-            summer++;
387
-            return false;
424
+    private int summer = 0;
425
+    private boolean isSummer() {
426
+        if (summer == 3) {
427
+            return true;
388 428
         }
429
+        summer++;                
430
+        return false; 
431
+    }
432
+
389 433
     private void sendEmergencyText(String mesg, String phone) {
390 434
     }
391 435
 

+ 14
- 14
package.bluej 查看文件

@@ -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
8
+editor.fx.0.height=717
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=310
11
+editor.fx.0.y=23
12
+objectbench.height=92
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.8495440729483282
16
+package.editor.height=552
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=716
21 21
 package.frame.width=1265
22 22
 package.numDependencies=2
23 23
 package.numTargets=4