Browse Source

completed the program

thulasi 6 years ago
parent
commit
d5ecfd3ac7
3 changed files with 109 additions and 59 deletions
  1. 19
    8
      WriteIFs.java
  2. 77
    38
      WriteLoops.java
  3. 13
    13
      package.bluej

+ 19
- 8
WriteIFs.java View File

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

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

+ 13
- 13
package.bluej View File

@@ -5,20 +5,20 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=WriteIFsTest
6 6
 dependency2.to=WriteIFs
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=885
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.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 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true