#37 Curtis Cook

Aperto
CurtisMCook vorrebbe unire 1 commit da CurtisMCook/FirstSaturday:master a master
4 ha cambiato i file con 119 aggiunte e 38 eliminazioni
  1. 19
    5
      WriteIFs.java
  2. 86
    19
      WriteLoops.java
  3. 1
    1
      WriteLoopsTest.java
  4. 13
    13
      package.bluej

+ 19
- 5
WriteIFs.java Vedi File

7
  */
7
  */
8
 public class WriteIFs
8
 public class WriteIFs
9
 {
9
 {
10
+   int x;
11
+   int tt_t;
12
+   int tt_s;
13
+   int oo1, oo2;
14
+   String ss;
10
  
15
  
11
     public void playerDied(boolean player1) {
16
     public void playerDied(boolean player1) {
12
         // Write an IF statement that checks “player1.isAlive()” 
17
         // Write an IF statement that checks “player1.isAlive()” 
13
         // and if that’s false, calls “displayGameOver(player1)”
18
         // and if that’s false, calls “displayGameOver(player1)”
14
-     
19
+        if(!isAlive(player1)) {
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()”
21
-
22
-
28
+        if(room < 70) {
29
+            heatOn();
30
+        } else {
31
+            coolOn();
32
+        }
23
         
33
         
24
         return this.ss;
34
         return this.ss;
25
     }
35
     }
30
         // AND 
40
         // AND 
31
         // “insideTemp()” is less than 62, 
41
         // “insideTemp()” is less than 62, 
32
         // calls “startAFire(fireplace1)”
42
         // calls “startAFire(fireplace1)”
33
-
43
+        if(outsideTemp() < 50 || insideTemp() < 62) {
44
+            startAFire(fireplace1);
45
+        }
34
     }
46
     }
35
 
47
 
36
     public void checkFuel(double fuelLevel) {
48
     public void checkFuel(double fuelLevel) {
37
         // Write an IF statement that checks “fuelLevel” 
49
         // Write an IF statement that checks “fuelLevel” 
38
         // and if that check is less than 0.08, calls “refuel()”
50
         // and if that check is less than 0.08, calls “refuel()”
39
-
51
+        if(fuelLevel < 0.08) {
52
+            refuel();
53
+        }
40
     }
54
     }
41
 
55
 
42
 
56
 

+ 86
- 19
WriteLoops.java Vedi File

20
 
20
 
21
         // Write a FOR loop that counts from 1 to 10.
21
         // Write a FOR loop that counts from 1 to 10.
22
             // calling
22
             // calling
23
-            w = w + 1;
23
+            // w = w + 1;
24
             // each time through the loop
24
             // each time through the loop
25
 
25
 
26
         // this will tell the test how many times the loop executed.
26
         // this will tell the test how many times the loop executed.
27
+        
28
+        for(int i = 0; i < 5; i++) {
29
+            w += 1;
30
+        }
31
+
27
         return w;
32
         return w;
28
     }
33
     }
29
 
34
 
32
 
37
 
33
         // Write a FOR loop that counts from 1 to 10.
38
         // Write a FOR loop that counts from 1 to 10.
34
         // calling
39
         // calling
35
-        w = w + 1;
40
+        // w = w + 1;
36
         // each time through the loop
41
         // each time through the loop
37
         
42
         
43
+        for(int i = 0; i < 10; i++) {
44
+            w += 1;
45
+        }
46
+        
38
         return w;
47
         return w;
39
     }
48
     }
40
 
49
 
43
 
52
 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
53
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
54
         // calling
46
-        w = w + 1;
55
+        // w = w + 1;
47
         // each time through the loop
56
         // each time through the loop
48
         
57
         
58
+        for(int i = 21; i <= 31; i++) {
59
+            w += 1;
60
+        }
61
+        
49
         return w;
62
         return w;
50
     }
63
     }
51
 
64
 
54
 
67
 
55
         // Write a FOR loop that counts down from 100 to 0.
68
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
69
         // calling
57
-        w = w + 1;
70
+        // w = w + 1;
58
         // each time through the loop
71
         // each time through the loop
72
+        for(int i = 100; i > 0; i--) {
73
+            w += 1;
74
+        }
59
         
75
         
60
         return w;
76
         return w;
61
     }
77
     }
65
 
81
 
66
         // Write a FOR loop from 0 to 32 by 2s.
82
         // Write a FOR loop from 0 to 32 by 2s.
67
         // calling
83
         // calling
68
-        w = w + 1;
84
+        // w = w + 1;
69
         // each time through the loop
85
         // each time through the loop
86
+        for(int i = 0; i < 32; i += 2) {
87
+            w += 1;
88
+        }
89
+        
70
         return w;
90
         return w;
71
     }
91
     }
72
 
92
 
75
 
95
 
76
         // Write a FOR loop from 1 to less than 5001 by 11s.
96
         // Write a FOR loop from 1 to less than 5001 by 11s.
77
         // calling
97
         // calling
78
-        w = w + 1;
98
+        // w = w + 1;
79
         // each time through the loop
99
         // each time through the loop
80
-        
100
+
101
+        for(int i = 1; i < 5001; i += 11) {
102
+            w += 1;
103
+        }
104
+       
81
         return w;
105
         return w;
82
     }
106
     }
83
 
107
 
87
         // Write a nested FOR loop(s), where one counts from
111
         // 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
112
         // 0 to less than 20 and the inner one counts from 0 to 4
89
                 // calling
113
                 // calling
90
-                w = w + 1;
114
+                // w = w + 1;
91
                 // each time through the inner loop
115
                 // each time through the inner loop
116
+                
117
+                
118
+
119
+      for(int i = 0; i < 20; i++) {
120
+          for(int j = 0; j <= 4; j++) {
121
+              w += 1;
122
+            }
123
+        }
124
+                
92
 
125
 
93
         return w;
126
         return w;
94
     }
127
     }
102
         // prints “Hello Zipcode” instead of the statement w = w + 1;
135
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103
 
136
 
104
                 // calling
137
                 // calling
105
-                w = w + 1;
138
+                // w = w + 1;
106
             // each time through the inner loop
139
             // each time through the inner loop
107
         
140
         
141
+            
142
+            for(int i = 5; i < 105; i++) {
143
+                if(i <= 51) {
144
+                    System.out.println("Hello Zipcode");
145
+                    w += 1;
146
+                }
147
+            }
108
         return w;
148
         return w;
109
     }
149
     }
110
 
150
 
113
 
153
 
114
         // sample while loop
154
         // sample while loop
115
         while (i <= 5) {
155
         while (i <= 5) {
116
-            System.out.println("Eww.");
117
-            i = i + 1;
156
+            System.out.println("Eww."); // 0, 1, 2, 3, 4, 5
157
+            i = i + 1; // 1, 2, 3, 4, 5, 6
118
         }
158
         }
119
 
159
 
120
         // sample do...while loop
160
         // sample do...while loop
121
         i = 8;
161
         i = 8;
122
         do {
162
         do {
123
-            System.out.println("Eww.");
124
-            i = i - 1;
163
+            System.out.println("Eww."); // 8, 7, 6, 5, 4, 3, 2, 1
164
+            i = i - 1;// 7, 6, 5, 4, 3, 2, 1, 0
125
         } while (i > 0);
165
         } while (i > 0);
126
         // what's the primary difference between them?!?
166
         // what's the primary difference between them?!?
167
+        // The condition is checked at the begining for the while loop and at the end of the do while
168
+        // loop.  This guarantees that the do while loop will be run at least once.
127
     }
169
     }
128
 
170
 
129
     // Write a WHILE loop that checks “gpsCurrentLocation()”
171
     // Write a WHILE loop that checks “gpsCurrentLocation()”
135
         // you need to use a .equals for two Strings.
177
         // you need to use a .equals for two Strings.
136
 
178
 
137
             // calling
179
             // calling
138
-            w = w + 1;
180
+            //w = w + 1;
139
             // each time through the inner loop
181
             // each time through the inner loop
140
-        
182
+        while(!gpsCurrentLocation().equals("Home")) {
183
+            driveSomeMore();
184
+            w += 1;
185
+        }
186
+        System.out.println("Honey, I'm Home!");
141
 
187
 
142
             return w;
188
             return w;
143
     }
189
     }
157
         // do your while loop here
203
         // do your while loop here
158
  
204
  
159
             // calling
205
             // calling
160
-            w = w + 1;
206
+            //w = w + 1;
161
             // each time through the inner loop
207
             // each time through the inner loop
162
         
208
         
209
+        while(runningScore < highestScore) {
210
+            runningScore += currentScore;
211
+            currentScore = gameNextScore();
212
+            w += 1;
213
+        }
214
+            
163
         return w; // >= 3;
215
         return w; // >= 3;
164
     }
216
     }
165
 
217
 
174
         // do your while loop here
226
         // do your while loop here
175
 
227
 
176
             // calling
228
             // calling
177
-            w = w + 1;
229
+            // w = w + 1;
178
             // each time through the inner loop
230
             // each time through the inner loop
179
-
231
+            
232
+                
233
+        do {
234
+            runningScore += currentScore;
235
+            currentScore = gameNextScore();
236
+            w += 1;  
237
+        } while(runningScore < highestScore);
238
+        System.out.print("Number of times through the loop is " + w);
180
         return w >= 3;
239
         return w >= 3;
181
     }
240
     }
182
 
241
 
190
         
249
         
191
 
250
 
192
         // calling
251
         // calling
193
-        w = w + 1;
252
+        // w = w + 1;
194
         // each time through the inner loop
253
         // each time through the inner loop
254
+        while(serverIsRunning()) {
255
+            waitFor(5);
256
+            w += 1;
257
+        }
195
         
258
         
259
+        if(!serverIsRunning()) {            
260
+            tryServerRestart("Help!", adminPhoneNumber);
261
+        }
196
         return w;
262
         return w;
197
     }
263
     }
198
 
264
 
201
     // and if it is, add 7 to “i”
267
     // and if it is, add 7 to “i”
202
     public int loop50by7() {
268
     public int loop50by7() {
203
         int w = 0;
269
         int w = 0;
270
+        int i = 7;
204
 
271
 
205
 
272
 
206
             // calling
273
             // calling

+ 1
- 1
WriteLoopsTest.java Vedi File

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

+ 13
- 13
package.bluej Vedi File

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
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=835
9
+editor.fx.0.width=1044
10
+editor.fx.0.x=396
11
+editor.fx.0.y=23
12
+objectbench.height=111
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.8498727735368957
16
+package.editor.height=661
17
 package.editor.width=1139
17
 package.editor.width=1139
18
 package.editor.x=112
18
 package.editor.x=112
19
-package.editor.y=89
19
+package.editor.y=56
20
 package.frame.height=844
20
 package.frame.height=844
21
 package.frame.width=1265
21
 package.frame.width=1265
22
 package.numDependencies=2
22
 package.numDependencies=2