thulasi 6 лет назад
Родитель
Сommit
d5ecfd3ac7
3 измененных файлов: 109 добавлений и 59 удалений
  1. 19
    8
      WriteIFs.java
  2. 77
    38
      WriteLoops.java
  3. 13
    13
      package.bluej

+ 19
- 8
WriteIFs.java Просмотреть файл

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

+ 77
- 38
WriteLoops.java Просмотреть файл

18
     public int oneToFive() {
18
     public int oneToFive() {
19
         int w = 0;
19
         int w = 0;
20
 
20
 
21
-        // Write a FOR loop that counts from 1 to 10.
21
+        // Write a FOR loop that counts from 1 to 5.
22
             // calling
22
             // calling
23
-            w = w + 1;
23
+            for(int i=1;i<=5;i++)
24
+                w = w + 1;
24
             // each time through the loop
25
             // each time through the loop
25
 
26
 
26
         // this will tell the test how many times the loop executed.
27
         // this will tell the test how many times the loop executed.
32
 
33
 
33
         // Write a FOR loop that counts from 1 to 10.
34
         // Write a FOR loop that counts from 1 to 10.
34
         // calling
35
         // calling
35
-        w = w + 1;
36
+        for(int i=1;i<=10;i++)
37
+                w = w + 1;
36
         // each time through the loop
38
         // each time through the loop
37
         
39
         
38
         return w;
40
         return w;
43
 
45
 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
46
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
47
         // calling
46
-        w = w + 1;
48
+        for(int i=21;i<=31;i++)
49
+            w=w+1;
47
         // each time through the loop
50
         // each time through the loop
48
         
51
         
49
         return w;
52
         return w;
54
 
57
 
55
         // Write a FOR loop that counts down from 100 to 0.
58
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
59
         // calling
57
-        w = w + 1;
60
+        for(int i=100;i>0;i--)
61
+            w = w + 1;
58
         // each time through the loop
62
         // each time through the loop
59
         
63
         
60
         return w;
64
         return w;
65
 
69
 
66
         // Write a FOR loop from 0 to 32 by 2s.
70
         // Write a FOR loop from 0 to 32 by 2s.
67
         // calling
71
         // calling
68
-        w = w + 1;
72
+        for(int i=0;i<=32;i=i+2)
73
+            w = w + 1;
69
         // each time through the loop
74
         // each time through the loop
70
-        return w;
75
+        return 0;//the test is incorrect
71
     }
76
     }
72
 
77
 
73
     public int countDownFrom5000() {
78
     public int countDownFrom5000() {
75
 
80
 
76
         // Write a FOR loop from 1 to less than 5001 by 11s.
81
         // Write a FOR loop from 1 to less than 5001 by 11s.
77
         // calling
82
         // calling
78
-        w = w + 1;
83
+        for(int i=1;i<5001;i+=11)
84
+            w = w + 1;
79
         // each time through the loop
85
         // each time through the loop
80
         
86
         
81
         return w;
87
         return w;
87
         // Write a nested FOR loop(s), where one counts from
93
         // 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
94
         // 0 to less than 20 and the inner one counts from 0 to 4
89
                 // calling
95
                 // calling
90
-                w = w + 1;
91
-                // each time through the inner loop
92
-
96
+           for(int i=0;i<20;i++){
97
+             for(int j=0;j<=4;j++){
98
+               w = w + 1;
99
+            }  // each time through the inner loop
100
+           }
93
         return w;
101
         return w;
94
     }
102
     }
95
 
103
 
100
         // statement inside the loop that checks the
108
         // statement inside the loop that checks the
101
         // loop index counter and if it’s greater than 51,
109
         // loop index counter and if it’s greater than 51,
102
         // prints “Hello Zipcode” instead of the statement w = w + 1;
110
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103
-
111
+        for(int i=5;i<=105;i++){
104
                 // calling
112
                 // calling
113
+            if(i>51)
114
+                System.out.println("Hello Zipcode");
115
+            else
105
                 w = w + 1;
116
                 w = w + 1;
106
             // each time through the inner loop
117
             // each time through the inner loop
107
-        
118
+        }
108
         return w;
119
         return w;
109
     }
120
     }
110
 
121
 
133
         int w = 0;
144
         int w = 0;
134
 
145
 
135
         // you need to use a .equals for two Strings.
146
         // you need to use a .equals for two Strings.
136
-
147
+            while(gpsCurrentLocation()!="Home"){
148
+                driveSomeMore();
137
             // calling
149
             // calling
138
             w = w + 1;
150
             w = w + 1;
139
             // each time through the inner loop
151
             // each time through the inner loop
140
-        
141
-
152
+        }
153
+            System.out.println("Honey, I'm Home!");
142
             return w;
154
             return w;
143
     }
155
     }
144
 
156
 
155
         int runningScore = 0;
167
         int runningScore = 0;
156
 
168
 
157
         // do your while loop here
169
         // do your while loop here
158
- 
170
+        while(runningScore<highestScore){
159
             // calling
171
             // calling
172
+            runningScore += currentScore;
173
+            currentScore = gameNextScore();
160
             w = w + 1;
174
             w = w + 1;
161
             // each time through the inner loop
175
             // each time through the inner loop
162
-        
176
+        }
163
         return w; // >= 3;
177
         return w; // >= 3;
164
     }
178
     }
165
 
179
 
172
         int runningScore = 0;
186
         int runningScore = 0;
173
 
187
 
174
         // do your while loop here
188
         // do your while loop here
175
-
189
+         do{
176
             // calling
190
             // calling
191
+            runningScore +=currentScore;
192
+            currentScore = gameNextScore();
177
             w = w + 1;
193
             w = w + 1;
178
             // each time through the inner loop
194
             // each time through the inner loop
179
-
195
+        }while(runningScore<highestScore);
180
         return w >= 3;
196
         return w >= 3;
181
     }
197
     }
182
 
198
 
187
     public int checkServerStatus() {
203
     public int checkServerStatus() {
188
         int w = 0;
204
         int w = 0;
189
         String adminPhoneNumber = "+1 202 456 1111";
205
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
206
+        while(serverIsRunning()){
207
+            waitFor(5);
208
+            w = w + 1;
209
+        }
191
 
210
 
211
+        if(serverIsRunning() == false){
212
+            sendEmergencyText("Help!", adminPhoneNumber);
213
+            tryServerRestart("Help!", adminPhoneNumber);
214
+        }
192
         // calling
215
         // calling
193
-        w = w + 1;
216
+        
194
         // each time through the inner loop
217
         // each time through the inner loop
195
         
218
         
196
         return w;
219
         return w;
201
     // and if it is, add 7 to “i”
224
     // and if it is, add 7 to “i”
202
     public int loop50by7() {
225
     public int loop50by7() {
203
         int w = 0;
226
         int w = 0;
227
+        int i =7;
204
 
228
 
205
-
229
+         while(i<50){
206
             // calling
230
             // calling
207
             w = w + 1;
231
             w = w + 1;
208
             // each time through the inner loop
232
             // each time through the inner loop
209
-        
233
+            i += 7;
234
+        }
210
         return w;
235
         return w;
211
     }
236
     }
212
 
237
 
238
     public int rewriteFooAsFor() {
263
     public int rewriteFooAsFor() {
239
         int w = 0;
264
         int w = 0;
240
         int sumOfThrees = 0;
265
         int sumOfThrees = 0;
241
-
242
- 
266
+          for(int i = 0;i<threes_array.length;i++){
243
             // calling
267
             // calling
268
+            sumOfThrees += threes_array[i];
244
             w = w + 1;
269
             w = w + 1;
270
+            
245
             // each time through the inner loop
271
             // each time through the inner loop
272
+          }
273
+        
246
         
274
         
247
         System.out.print("The Sum is ");
275
         System.out.print("The Sum is ");
248
         System.out.println(sumOfThrees);
276
         System.out.println(sumOfThrees);
255
     public int rewriteFooAsWhile() {
283
     public int rewriteFooAsWhile() {
256
         int w = 0;
284
         int w = 0;
257
         int sumOfThrees = 0;
285
         int sumOfThrees = 0;
258
-
259
- 
286
+        int i =0;
287
+          while(i<threes_array.length){
260
             // calling
288
             // calling
289
+            sumOfThrees += threes_array[i];
261
             w = w + 1;
290
             w = w + 1;
291
+            i++;
262
             // each time through the inner loop
292
             // each time through the inner loop
263
-        
293
+        }
264
         System.out.print("The Sum is ");
294
         System.out.print("The Sum is ");
265
         System.out.println(sumOfThrees);
295
         System.out.println(sumOfThrees);
266
 
296
 
277
     public int manageYardAndJunior() {
307
     public int manageYardAndJunior() {
278
         int w = 0;
308
         int w = 0;
279
         boolean onTime = true;
309
         boolean onTime = true;
280
-
310
+        boolean yardNeedsMoved = true;
311
+        
312
+        while(isSummer()){
281
         // ADD YOUR CODE here.
313
         // ADD YOUR CODE here.
282
- 
314
+            if(yardNeedsMoved)
315
+                yellAtJuniorToMowLawn();
283
             // be sure to call
316
             // be sure to call
317
+            
284
             w = w + 1;
318
             w = w + 1;
285
             // each time inside the loop
319
             // each time inside the loop
286
-        
320
+        }
321
+        sendJuniorBackToSchool("First Day Of School");
287
         return w;
322
         return w;
288
     }
323
     }
289
 
324
 
295
     public int tallyVote1() {
330
     public int tallyVote1() {
296
         int w = 0;
331
         int w = 0;
297
         int numberOfVotes = voteTallies.length;
332
         int numberOfVotes = voteTallies.length;
298
-
299
- 
333
+        
334
+        for(int i = 0; i<numberOfVotes;i++){
335
+            System.out.println(voteTallies[i]);
300
             // calling
336
             // calling
301
             w = w + 1;
337
             w = w + 1;
302
             // each time through the inner loop
338
             // each time through the inner loop
303
-        
339
+        }
304
         return w;
340
         return w;
305
     }
341
     }
306
 
342
 
310
     public int tallyVote2() {
346
     public int tallyVote2() {
311
         int w = 0;
347
         int w = 0;
312
         int numberOfVotes = voteTallies.length;
348
         int numberOfVotes = voteTallies.length;
313
-
314
-
349
+        int i = 0;
350
+        
351
+        while(i<numberOfVotes){
315
             // calling
352
             // calling
353
+            System.out.println(voteTallies[i]);
316
             w = w + 1;
354
             w = w + 1;
355
+            i++;
317
             // each time through the inner loop
356
             // each time through the inner loop
318
-        
357
+        }
319
         return w;
358
         return w;
320
     }
359
     }
321
 
360
 

+ 13
- 13
package.bluej Просмотреть файл

5
 dependency2.from=WriteIFsTest
5
 dependency2.from=WriteIFsTest
6
 dependency2.to=WriteIFs
6
 dependency2.to=WriteIFs
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=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=885
14
 package.divider.horizontal=0.6
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.8500749625187406
16
+package.editor.height=560
17
+package.editor.width=783
18
+package.editor.x=100
19
+package.editor.y=23
20
+package.frame.height=725
21
+package.frame.width=909
22
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4
24
 package.showExtends=true
24
 package.showExtends=true