Explorar el Código

finished first saturday lab

Jonathan Hinds hace 8 años
padre
commit
63cfa4b662
Se han modificado 3 ficheros con 172 adiciones y 109 borrados
  1. 32
    13
      WriteIFs.java
  2. 126
    82
      WriteLoops.java
  3. 14
    14
      package.bluej

+ 32
- 13
WriteIFs.java Ver fichero

7
  */
7
  */
8
 public class WriteIFs
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
     public void playerDied(boolean player1) {
15
     public void playerDied(boolean player1) {
12
         // Write an IF statement that checks “player1.isAlive()” 
16
         // Write an IF statement that checks “player1.isAlive()” 
13
         // and if that’s false, calls “displayGameOver(player1)”
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
     public String thermoSTAT(int room) {
24
     public String thermoSTAT(int room) {
18
         // Write an IF statement that checks the 
25
         // Write an IF statement that checks the 
19
         // “temperature(room)” and if that check is less than 70, 
26
         // “temperature(room)” and if that check is less than 70, 
20
         // calls “heatOn()” else calls “coolOn()”
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
         return this.ss;
35
         return this.ss;
25
     }
36
     }
26
 
37
 
30
         // AND 
41
         // AND 
31
         // “insideTemp()” is less than 62, 
42
         // “insideTemp()” is less than 62, 
32
         // calls “startAFire(fireplace1)”
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
     public void checkFuel(double fuelLevel) {
51
     public void checkFuel(double fuelLevel) {
37
         // Write an IF statement that checks “fuelLevel” 
52
         // Write an IF statement that checks “fuelLevel” 
38
         // and if that check is less than 0.08, calls “refuel()”
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
      *  Pay no attention to the code below this point.
62
      *  Pay no attention to the code below this point.
47
      * 
64
      * 
48
      * instance variables
65
      * instance variables
49
      * / 
66
      * / 
67
+     * 
50
    int x;
68
    int x;
51
    int tt_t;
69
    int tt_t;
52
    int tt_s;
70
    int tt_s;
57
   /**
75
   /**
58
    * Constructor for objects of class WriteIFs
76
    * Constructor for objects of class WriteIFs
59
    */
77
    */
78
+  
60
   public WriteIFs()
79
   public WriteIFs()
61
   {
80
   {
62
       // initialise instance variables
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
     // associated routines
90
     // associated routines

+ 126
- 82
WriteLoops.java Ver fichero

1
 import com.sun.org.apache.xpath.internal.SourceTree;
1
 import com.sun.org.apache.xpath.internal.SourceTree;
2
-
3
 import java.awt.SystemTray;
2
 import java.awt.SystemTray;
4
 import java.util.concurrent.ThreadLocalRandom;
3
 import java.util.concurrent.ThreadLocalRandom;
5
 import java.util.function.Supplier;
4
 import java.util.function.Supplier;
19
         int w = 0;
18
         int w = 0;
20
 
19
 
21
         // Write a FOR loop that counts from 1 to 10.
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
         // this will tell the test how many times the loop executed.
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
         return w;
31
         return w;
28
     }
32
     }
29
 
33
 
34
         // calling
38
         // calling
35
         w = w + 1;
39
         w = w + 1;
36
         // each time through the loop
40
         // each time through the loop
37
-        
41
+
42
+        for(int i = 1; i < 10; i ++){
43
+            w = w + 1;
44
+        }
45
+
38
         return w;
46
         return w;
39
     }
47
     }
40
 
48
 
43
 
51
 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
52
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
53
         // calling
46
-        w = w + 1;
54
+        for(int i = 21; i < 32; i ++)
55
+        {
56
+            w = w + 1;
57
+        }
47
         // each time through the loop
58
         // each time through the loop
48
-        
59
+
49
         return w;
60
         return w;
50
     }
61
     }
51
 
62
 
54
 
65
 
55
         // Write a FOR loop that counts down from 100 to 0.
66
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
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
         return w;
72
         return w;
61
     }
73
     }
62
 
74
 
63
     public int byTwoTo32() {
75
     public int byTwoTo32() {
64
         int w = 0;
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
         return w;
81
         return w;
71
     }
82
     }
72
 
83
 
73
     public int countDownFrom5000() {
84
     public int countDownFrom5000() {
74
         int w = 0;
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
         return w;
91
         return w;
82
     }
92
     }
83
 
93
 
86
 
96
 
87
         // Write a nested FOR loop(s), where one counts from
97
         // 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
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
         return w;
110
         return w;
94
     }
111
     }
95
 
112
 
101
         // loop index counter and if it’s greater than 51,
118
         // loop index counter and if it’s greater than 51,
102
         // prints “Hello Zipcode” instead of the statement w = w + 1;
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
                 w = w + 1;
131
                 w = w + 1;
106
-            // each time through the inner loop
107
-        
132
+            }
133
+        }
134
+
108
         return w;
135
         return w;
109
     }
136
     }
110
 
137
 
133
         int w = 0;
160
         int w = 0;
134
 
161
 
135
         // you need to use a .equals for two Strings.
162
         // you need to use a .equals for two Strings.
136
-
163
+        while(!gpsCurrentLocation().equals("Home"))
164
+        {
137
             // calling
165
             // calling
138
             w = w + 1;
166
             w = w + 1;
139
             // each time through the inner loop
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
     // Getting harder...
175
     // Getting harder...
149
     // "runningScore"
179
     // "runningScore"
150
     // and then sets “currentScore” to “gameNextScore()”
180
     // and then sets “currentScore” to “gameNextScore()”
151
     public int checkGameScore() {
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
         // do your while loop here
187
         // do your while loop here
158
- 
159
-            // calling
188
+    while(runningScore < highestScore){
189
+        if(runningScore < highestScore)
190
+        {
191
+            runningScore += currentScore;
160
             w = w + 1;
192
             w = w + 1;
161
-            // each time through the inner loop
193
+        }
194
+        currentScore = gameNextScore();
162
         
195
         
196
+    }
163
         return w; // >= 3;
197
         return w; // >= 3;
164
     }
198
     }
165
 
199
 
171
         int currentScore = gameNextScore();
205
         int currentScore = gameNextScore();
172
         int runningScore = 0;
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
         return w >= 3;
216
         return w >= 3;
181
     }
217
     }
182
 
218
 
187
     public int checkServerStatus() {
223
     public int checkServerStatus() {
188
         int w = 0;
224
         int w = 0;
189
         String adminPhoneNumber = "+1 202 456 1111";
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
         return w;
239
         return w;
197
     }
240
     }
198
 
241
 
201
     // and if it is, add 7 to “i”
244
     // and if it is, add 7 to “i”
202
     public int loop50by7() {
245
     public int loop50by7() {
203
         int w = 0;
246
         int w = 0;
204
-
205
-
206
-            // calling
247
+        int i = 7;
248
+        while(i < 50){
249
+            i += 7;
207
             w = w + 1;
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
         return w;
257
         return w;
211
     }
258
     }
212
 
259
 
239
         int w = 0;
286
         int w = 0;
240
         int sumOfThrees = 0;
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
         System.out.print("The Sum is ");
293
         System.out.print("The Sum is ");
248
         System.out.println(sumOfThrees);
294
         System.out.println(sumOfThrees);
249
 
295
 
256
         int w = 0;
302
         int w = 0;
257
         int sumOfThrees = 0;
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
         System.out.print("The Sum is ");
309
         System.out.print("The Sum is ");
265
         System.out.println(sumOfThrees);
310
         System.out.println(sumOfThrees);
266
 
311
 
279
         boolean onTime = true;
324
         boolean onTime = true;
280
 
325
 
281
         // ADD YOUR CODE here.
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
         return w;
332
         return w;
288
     }
333
     }
289
 
334
 
296
         int w = 0;
341
         int w = 0;
297
         int numberOfVotes = voteTallies.length;
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
         return w;
348
         return w;
305
     }
349
     }
306
 
350
 
311
         int w = 0;
355
         int w = 0;
312
         int numberOfVotes = voteTallies.length;
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
         return w;
362
         return w;
320
     }
363
     }
321
 
364
 
378
     //         return (i >= 3);
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
     private void sendEmergencyText(String mesg, String phone) {
433
     private void sendEmergencyText(String mesg, String phone) {
390
     }
434
     }
391
 
435
 

+ 14
- 14
package.bluej Ver fichero

1
 #BlueJ package file
1
 #BlueJ package file
2
-dependency1.from=WriteLoopsTest
3
-dependency1.to=WriteLoops
2
+dependency1.from=WriteIFsTest
3
+dependency1.to=WriteIFs
4
 dependency1.type=UsesDependency
4
 dependency1.type=UsesDependency
5
-dependency2.from=WriteIFsTest
6
-dependency2.to=WriteIFs
5
+dependency2.from=WriteLoopsTest
6
+dependency2.to=WriteLoops
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
8
+editor.fx.0.height=717
9
 editor.fx.0.width=800
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
 package.divider.horizontal=0.6
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
 package.editor.width=1139
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
 package.frame.width=1265
21
 package.frame.width=1265
22
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4