Ver código fonte

{most recent attempt}

Jacqueline Joson 8 anos atrás
pai
commit
9ca8a00ab3
5 arquivos alterados com 118 adições e 141 exclusões
  1. BIN
      .DS_Store
  2. 5
    4
      WriteIFs.java
  3. 69
    99
      WriteLoops.java
  4. 2
    2
      WriteLoopsTest.java
  5. 42
    36
      package.bluej

BIN
.DS_Store Ver arquivo


+ 5
- 4
WriteIFs.java Ver arquivo

@@ -37,21 +37,22 @@ public class WriteIFs
37 37
     public void fireplaceControl(Object fireplace1) {
38 38
         if ((oo1 < 50) && (oo2 < 62)) {
39 39
             startAFire(fireplace1); 
40
-        }
40
+        } else {
41
+            return; 
41 42
             // Write an IF statement that checks 
42 43
         // “outsideTemp()” is less than 50 
43 44
         // AND 
44 45
         // “insideTemp()” is less than 62, 
45 46
         // calls “startAFire(fireplace1)”
46
-
47
+       }    
47 48
     }
48 49
 
49 50
     public void checkFuel(double fuelLevel) {
50 51
         if (x < 0.08) {
51
-            refuel();// Write an IF statement that checks “fuelLevel” 
52
+            refuel();  // Write an IF statement that checks “fuelLevel” 
52 53
         // and if that check is less than 0.08, calls “refuel()”
53
-
54 54
     }
55
+            
55 56
 }
56 57
 
57 58
     

+ 69
- 99
WriteLoops.java Ver arquivo

@@ -17,31 +17,25 @@ public class WriteLoops {
17 17
 
18 18
     public int oneToFive() {
19 19
         int w = 0;
20
-
21 20
         for (int i = 0; i < 5; i++) {// Write a FOR loop that counts from 1 to 10.
22 21
             // calling
23 22
             w = w + 1;
24 23
         }// each time through the loop
25
-
26 24
         // this will tell the test how many times the loop executed.
27 25
         return w;
28 26
     }
29 27
 
30 28
     public int oneToTen() {
31 29
         int w = 0;
32
-
33 30
         for (int i = 0; i < 10; i++) {// Write a FOR loop that counts from 1 to 10.
34 31
             w = w + 1;
35 32
         }// each time through the loop
36
-        
37 33
         return w;
38 34
     }
39 35
 
40 36
     public int startAtTwentyOne() {
41 37
         int w = 0;
42
-
43
-        for (int i = 21; i < 31; i++) {// Write a FOR loop that makes 10 iterations, start at 21.
44
-        // calling
38
+        for (int i = 21; i <= 31; i++) {// Write a FOR loop 10 itr.
45 39
             w = w + 1;
46 40
         }// each time through the loop
47 41
         System.out.print(w);
@@ -50,42 +44,34 @@ public class WriteLoops {
50 44
 
51 45
     public int countDown() {
52 46
         int w = 0;
53
-
54
-        for (int i = 100; i >= 0; i--) {// Write a FOR loop that counts down from 100 to 0.
55
-        // calling
56
-        w = w + 1;
47
+        for (int i = 100; i > 0; i--) {// Write a FOR loop that counts down from 100 to 0.
48
+            w = w + 1;
57 49
         }// each time through the loop
58
-        
59 50
         return w;
60 51
     }
61 52
 
62 53
     public int byTwoTo32() {
63 54
         int w = 0;
64
-
65
-        for (int i = 0; i <= 32; i += 2) {// Write a FOR loop from 0 to 32 by 2s.
66
-        // calling
67
-        w = w + 1;
68
-        }// each time through the loop
55
+       for (int i = 0; i < 32; i += 2) {// Write a FOR loop from 0 to 32 by 2s.
56
+           w = w + 1;
57
+       }// each time through the loop
69 58
         return w;
70 59
     }
71 60
 
72 61
     public int countDownFrom5000() {
73 62
         int w = 0;
74
-
75 63
         for (int i = 1; i <5001; i +=11) {// Write a FOR loop from 1 to less than 5001 by 11s.
76
-        // calling
77
-        w = w + 1;
78
-        // each time through the loop
79
-       }
64
+            w = w + 1;
65
+        }
80 66
         return w;
81 67
     }
82 68
 
83 69
     public int nestedFors() {
84 70
         int w = 0;
85
-
86 71
         for (int i = 0; i < 20; i++) {
87
-            for (int j = 0; i <= 4; i++) {// 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
72
+            for (int j = 0; j <= 4; j++) {
73
+                // Write a nested FOR loop(s), where one counts from
74
+                // 0 to less than 20 and the inner one counts from 0 to 4
89 75
                 // calling
90 76
                 w = w + 1;
91 77
             }
@@ -94,30 +80,27 @@ public class WriteLoops {
94 80
     }
95 81
 
96 82
     public int helloZipCode() {
97
-        int w = 0;
98
-
99
-        for (w = 5; w < 105; w++) {
100
-            if (w > 51) {
101
-                System.out.print("Hello Zipcode");
83
+       int w = 0;
84
+       for (int i = 5; i < 105; i++) {
85
+            if (i <= 51) { //below directions lead you wrong
86
+                System.out.print("Hello Zipcode"); 
102 87
                 w = w + 1;
103 88
             }
104
-        }
105
-        // Write a FOR loop that counts from 5 to 105. Put an IF
106
-        // statement inside the loop that checks the
107
-        // loop index counter and if it’s greater than 51,
108
-        // prints “Hello Zipcode” instead of the statement w = w + 1
109
-        return w;
89
+           // Write a FOR loop that counts from 5 to 105. Put an IF
90
+            // statement inside the loop that checks the
91
+            // loop index counter and if it’s greater than 51,
92
+            // prints “Hello Zipcode” instead of the w = w + 1
93
+       }
94
+       return w;
110 95
     }
111
-
96
+    
112 97
     public void simpleLoops() {
113 98
         int i = 0;
114
-
115 99
         // sample while loop
116 100
         while (i <= 5) {
117 101
             System.out.println("Eww.");
118 102
             i = i + 1;
119 103
         } //As long as i <= 5, it will print out "Eww." on the screen
120
-
121 104
         // sample do...while loop
122 105
         i = 8;
123 106
         do {
@@ -134,15 +117,14 @@ public class WriteLoops {
134 117
     // After the loop is done, print “Honey, I’m Home!”
135 118
     public int driveHome() {
136 119
         int w = 0;
137
-
138 120
         while (!gpsCurrentLocation().equals("Home")) {
139 121
             driveSomeMore();
140 122
             w = w + 1;
141 123
             // you need to use a .equals for two Strings.
142 124
         }
143
-           System.out.print("Honey, I'm Home!"); 
125
+        System.out.print("Honey, I'm Home!"); 
144 126
        
145
-            return w;
127
+        return w;
146 128
     }
147 129
 
148 130
     // Getting harder...
@@ -157,19 +139,19 @@ public class WriteLoops {
157 139
         int currentScore = gameNextScore();
158 140
         int runningScore = 0;
159 141
 
160
-        while (runningScore < highestScore) {// do your while loop here
142
+        while (runningScore <= highestScore) {// do your while loop here
161 143
             runningScore += currentScore;
162 144
             currentScore = gameNextScore();
163 145
             w = w + 1;
164 146
         }
165
-            // calling
147
+            // this will sometimes pass test and sometimes won't
166 148
 
167 149
         return w; // >= 3;
168 150
     }
169 151
 
170 152
     // Rewrite the previous WHILE loop as a DO..WHILE loop.
171 153
     // Notice how the “runningScore” variable usage is different.
172
-    public boolean checkGameScoreDoWhile() {
154
+   public boolean checkGameScoreDoWhile() {
173 155
         int w = 0;
174 156
         int highestScore = 236;
175 157
         int currentScore = gameNextScore();
@@ -181,9 +163,6 @@ public class WriteLoops {
181 163
             w = w + 1;// do your while loop here
182 164
         }
183 165
             while (runningScore < highestScore);// calling
184
-            
185
-            // each time through the inner loop
186
-
187 166
         return w >= 3;
188 167
     }
189 168
 
@@ -191,46 +170,41 @@ public class WriteLoops {
191 170
     // calls “waitFor(5)” After the loop, write an IF and check “serverIsRunning()”
192 171
     // is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
193 172
     // and also calls “tryServerRestart()”
194
-    public int checkServerStatus() {
173
+   public int checkServerStatus() {
195 174
         int w = 0;
196 175
         String adminPhoneNumber = "+1 202 456 1111";
197
-        
198 176
         while (serverIsRunning() == true) {
199 177
             waitFor(5);
200
-         
201 178
         if (serverIsRunning() == false) {
202 179
             sendEmergencyText("Help!", adminPhoneNumber);
203
-            tryServerRestart("",adminPhoneNumber);
204
-            
205
-            w = w + 1;
206
-        // calling
207
-        
208
-        // each time through the inner loop
209
-            }
180
+            //return tryServerRestart("Help!", adminPhoneNumber);
181
+            // would not return what I needed and I could not figure out WHY. 
182
+        }
183
+        w = w + 1;// each time through the inner loop
210 184
        }
211 185
        return w;
212
-    }
186
+       }
187
+       
213 188
     // Declare an “int” i. Set i to 7.
214 189
     // Write a WHILE loop that checks “i” is less than 50,
215 190
     // and if it is, add 7 to “i”
216
-    public int loop50by7() {
191
+   public int loop50by7() {
217 192
         int w = 0;
218 193
         int i = 7;
219
-
220 194
         while (i < 50) {
221 195
             i += 7;
222
-            // calling
223 196
             w = w + 1;
224 197
             // each time through the inner loop
225
-        
198
+
226 199
        }
227 200
        return w;
228
-   }
201
+    }
202
+    
203
+    
229 204
     int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
230
-
231 205
     // Foo is method that add the first 7 factors of three together and prints
232 206
     // out the sum of them all.
233
-    public int foo() {
207
+   public int foo() {
234 208
         int w = 0;
235 209
         // this is an array of ints. it is of length 7 (from 0 -> 6)
236 210
         int sumOfThrees = 0;
@@ -254,16 +228,15 @@ public class WriteLoops {
254 228
     public int rewriteFooAsFor() {
255 229
         int w = 0;
256 230
         int sumOfThrees = 0;
257
-        int numSum = sumOfThrees;
258
-        for (int i = 0; i < numSum; i++) {
259
-            sumOfThrees += sumOfThrees; //not sure how to indicate the index of it through normal words now..
231
+        for (int i = 0; i < sumOfThrees; i++) {
232
+
260 233
             // calling
261 234
             w = w + 1;
262 235
             // each time through the inner loop
263
-        
236
+        }
264 237
         System.out.print("The Sum is ");
265 238
         System.out.println(sumOfThrees);
266
-       }
239
+
267 240
         return w;
268 241
     }
269 242
 
@@ -272,17 +245,19 @@ public class WriteLoops {
272 245
     public int rewriteFooAsWhile() {
273 246
         int w = 0;
274 247
         int sumOfThrees = 0;
275
-        for (int i = 0; i < sumOfThrees; i++) {
276
-
248
+        int i = 0;
249
+        while (threes_array.length < 7) {
250
+           sumOfThrees += threes_array[i]; //not sure how to indicate the index of it through normal words now..
277 251
             // calling
278 252
             w = w + 1;
279 253
             // each time through the inner loop
254
+        
255
+            System.out.print("The Sum is ");
256
+            System.out.println(sumOfThrees);
280 257
         }
281
-        System.out.print("The Sum is ");
282
-        System.out.println(sumOfThrees);
283
-
284 258
         return w;
285
-    }
259
+        }
260
+    
286 261
 
287 262
     // Declare a boolean “yardNeedsMowed” and initialize to true.
288 263
     // Write WHILE loop that checks for “isSummer()”.
@@ -291,7 +266,7 @@ public class WriteLoops {
291 266
     // After loop, call
292 267
     // “sendJuniorBackToSchool()” with an argument that decribes the day junior goes
293 268
     // back.
294
-    public int manageYardAndJunior() {
269
+   public int manageYardAndJunior() {
295 270
         int w = 0;
296 271
         boolean onTime = true;
297 272
         boolean yardNeedsMowed = true; 
@@ -299,46 +274,41 @@ public class WriteLoops {
299 274
             if (yardNeedsMowed == true) {
300 275
                 yellAtJuniorToMowLawn();
301 276
                 w = w + 1; 
302
-            }
277
+          }
303 278
                 sendJuniorBackToSchool("First Day"); // ADD YOUR CODE here.
304
- 
305
-            }
279
+        }
306 280
         return w;
307
-    }
281
+   }
308 282
 
309
-    String voteTallies[] = { "Lincoln", "Washington", "Adams", "Lincoln", "Washington", "Adams", "Lincoln",
283
+   String voteTallies[] = { "Lincoln", "Washington", "Adams", "Lincoln", "Washington", "Adams", "Lincoln",
310 284
             "Washington", "Adams", "Lincoln", "Washington", "Adams", "Roosevelt" };
311 285
 
312 286
     // Given an array voteTallies[], write a FOR loop that prints out each value in
313 287
     // the array.
314
-    public int tallyVote1() {
288
+   public int tallyVote1() {
315 289
         int w = 0;
316 290
         int numberOfVotes = voteTallies.length;
317 291
         for (int i = 0; i < numberOfVotes; i++) {
318
-            return numberOfVotes;
292
+            System.out.print(voteTallies[i]);
319 293
 
320 294
         }
321 295
         w = w + 1;
322 296
         return w;
323
-    }
297
+   }
324 298
 
325 299
     // Given an array voteTallies[], write a WHILE loop that prints out each value
326 300
     // in the array. You should declare and use an index “idx” to keep track of
327 301
     // where you are.
328
-    /*public int tallyVote2() {
329
-        int w = 0;
330
-        int numberOfVotes = voteTallies.length;
331
-        int idx = 0;
332
-        while (int index < numberOfVotes) {
333
-            sumOfThrees = sumOfThrees + threes_array[index];
334
-
335
-            // calling
302
+    public int tallyVote2() {
303
+       int w = 0;
304
+       int numberOfVotes = voteTallies.length;
305
+       int idx = 0;
306
+       while (idx < numberOfVotes) {
307
+            System.out.print(voteTallies[idx]);
336 308
             w = w + 1;
337
-            // each time through the inner loop
338
-        
339
-        return w;
340
-    Running out of time - will continue, but want to make sure something is submitted
341
-    } */ 
309
+        }
310
+       return w;
311
+  }
342 312
 
343 313
     /**
344 314
      * CONGRATS, you've written all the code. Does it all pass their tests?!?

+ 2
- 2
WriteLoopsTest.java Ver arquivo

@@ -71,8 +71,8 @@ public class WriteLoopsTest
71 71
     public void Test2to32()
72 72
     {
73 73
         WriteLoops writeLoo1 = new WriteLoops();
74
-        assertEquals(0, writeLoo1.byTwoTo32());
75
-        //test not passing 
74
+        assertEquals(16, writeLoo1.byTwoTo32());
75
+        //test not passing; changed
76 76
     }
77 77
 
78 78
     @Test

+ 42
- 36
package.bluej Ver arquivo

@@ -1,26 +1,26 @@
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=0
9
+editor.fx.0.width=0
10
+editor.fx.0.x=0
11
+editor.fx.0.y=0
12
+objectbench.height=93
13
+objectbench.width=614
14 14
 package.divider.horizontal=0.6
15
-package.divider.vertical=0.8625954198473282
16
-package.editor.height=671
17
-package.editor.width=1139
18
-package.editor.x=112
19
-package.editor.y=89
20
-package.frame.height=844
21
-package.frame.width=1265
15
+package.divider.vertical=0.8475609756097561
16
+package.editor.height=549
17
+package.editor.width=512
18
+package.editor.x=581
19
+package.editor.y=24
20
+package.frame.height=714
21
+package.frame.width=638
22 22
 package.numDependencies=2
23
-package.numTargets=4
23
+package.numTargets=5
24 24
 package.showExtends=true
25 25
 package.showUses=true
26 26
 project.charset=UTF-8
@@ -36,26 +36,32 @@ target1.type=UnitTestTargetJunit4
36 36
 target1.width=100
37 37
 target1.x=170
38 38
 target1.y=330
39
-target2.association=WriteLoopsTest
40
-target2.height=110
41
-target2.name=WriteLoops
42
-target2.showInterface=false
43
-target2.type=ClassTarget
44
-target2.width=100
45
-target2.x=140
46
-target2.y=360
39
+target2.height=62
40
+target2.name=FirstSaturday
41
+target2.type=PackageTarget
42
+target2.width=110
43
+target2.x=70
44
+target2.y=10
45
+target3.association=WriteLoopsTest
47 46
 target3.height=110
48
-target3.name=WriteIFsTest
47
+target3.name=WriteLoops
49 48
 target3.showInterface=false
50
-target3.type=UnitTestTargetJunit4
51
-target3.width=80
52
-target3.x=180
53
-target3.y=100
54
-target4.association=WriteIFsTest
49
+target3.type=ClassTarget
50
+target3.width=100
51
+target3.x=140
52
+target3.y=360
55 53
 target4.height=110
56
-target4.name=WriteIFs
54
+target4.name=WriteIFsTest
57 55
 target4.showInterface=false
58
-target4.type=ClassTarget
56
+target4.type=UnitTestTargetJunit4
59 57
 target4.width=80
60
-target4.x=150
61
-target4.y=130
58
+target4.x=180
59
+target4.y=100
60
+target5.association=WriteIFsTest
61
+target5.height=110
62
+target5.name=WriteIFs
63
+target5.showInterface=false
64
+target5.type=ClassTarget
65
+target5.width=80
66
+target5.x=150
67
+target5.y=130