소스 검색

FirstSaturday

Soujanya Buragapu 6 년 전
부모
커밋
ff15fd5abc
4개의 변경된 파일219개의 추가작업 그리고 89개의 파일을 삭제
  1. 66
    12
      WriteIFs.java
  2. 17
    17
      WriteIFsTest.java
  3. 122
    46
      WriteLoops.java
  4. 14
    14
      package.bluej

+ 66
- 12
WriteIFs.java 파일 보기

@@ -7,36 +7,88 @@
7 7
  */
8 8
 public class WriteIFs
9 9
 {
10
+ private String ss;
11
+ private int tt_s;
12
+ private int oo1;
13
+ private int oo2;
14
+ private int x;
15
+public String getValueOfss()
16
+{
17
+    return this.ss;
18
+}
19
+public int getValueOfx()
20
+{
21
+    return this.x;
22
+}
23
+public int getValueOftts()
24
+{
25
+    return this.tt_s;
26
+}
27
+public void putValueOftts(int val)
28
+{
29
+    this.tt_s = val;
30
+}
31
+public void putValueOfoo1(int val)
32
+{
33
+    this.oo1 = val;
34
+}
35
+public void putValueOfoo2(int val)
36
+{
37
+    this.oo2 = val;
38
+}
10 39
  
11
-    public void playerDied(boolean player1) {
40
+    public void playerDied(boolean player1) 
41
+    {
12 42
         // Write an IF statement that checks “player1.isAlive()” 
43
+        boolean str = isAlive(player1);
44
+        
45
+        if (str == false)
46
+        {
47
+            displayGameOver(player1);
48
+        }
49
+        //return str;
50
+            
13 51
         // and if that’s false, calls “displayGameOver(player1)”
14
-     
15 52
     }
16 53
     
17
-    public String thermoSTAT(int room) {
54
+    public String thermoSTAT(int room) 
55
+    {
56
+        int temp = tempurature(room);
57
+        if (temp < 70)
58
+        {
59
+         heatOn();
60
+        }
61
+        else
62
+        {
63
+            coolOn();
64
+        }
18 65
         // Write an IF statement that checks the 
19 66
         // “temperature(room)” and if that check is less than 70, 
20 67
         // calls “heatOn()” else calls “coolOn()”
21
-
22
-
23
-        
24 68
         return this.ss;
25 69
     }
26 70
 
27
-    public void fireplaceControl(Object fireplace1) {
71
+    public void fireplaceControl(Object fireplace1) 
72
+    {
28 73
         // Write an IF statement that checks 
29 74
         // “outsideTemp()” is less than 50 
30 75
         // AND 
31 76
         // “insideTemp()” is less than 62, 
32 77
         // calls “startAFire(fireplace1)”
33
-
78
+        if (outsideTemp()<50 && insideTemp()<62)
79
+        {
80
+            startAFire(fireplace1);
81
+        }
34 82
     }
35 83
 
36 84
     public void checkFuel(double fuelLevel) {
37 85
         // Write an IF statement that checks “fuelLevel” 
38 86
         // and if that check is less than 0.08, calls “refuel()”
39
-
87
+        if(fuelLevel<0.08)
88
+        {
89
+            refuel();
90
+        }
91
+        
40 92
     }
41 93
 
42 94
 
@@ -61,7 +113,7 @@ public class WriteIFs
61 113
   {
62 114
       // initialise instance variables
63 115
       x = 0;
64
-      tt_t = 0;
116
+      //tt_t = 0;
65 117
       tt_s = 1;
66 118
       ss = "";
67 119
       oo1 = 61;
@@ -75,10 +127,12 @@ public class WriteIFs
75 127
     private int tempurature(int t) {
76 128
         return t+2;
77 129
     }
78
-    private void heatOn() {
130
+    private void heatOn() 
131
+    {
79 132
         this.ss = "heating";
80 133
     }
81
-    private void coolOn() {
134
+    private void coolOn() 
135
+    {
82 136
         this.ss = "cooling";
83 137
     }
84 138
  

+ 17
- 17
WriteIFsTest.java 파일 보기

@@ -48,7 +48,7 @@ public class WriteIFsTest
48 48
     {
49 49
         WriteIFs writeIFs1 = new WriteIFs();
50 50
         writeIFs1.playerDied(true);
51
-        assertEquals("Game Over!", writeIFs1.ss);
51
+        assertEquals("Game Over!", writeIFs1.getValueOfss());
52 52
     }
53 53
 
54 54
 
@@ -69,43 +69,43 @@ public class WriteIFsTest
69 69
     {
70 70
         WriteIFs writeIFs1 = new WriteIFs();
71 71
         writeIFs1.checkFuel(_0_5);
72
-        assertEquals(0, writeIFs1.x);
72
+        assertEquals(0, writeIFs1.getValueOfx());
73 73
     }
74 74
     @Test
75 75
     public void TestCheckFuel2()
76 76
     {
77 77
         WriteIFs writeIFs1 = new WriteIFs();
78 78
         writeIFs1.checkFuel(_0_04);
79
-        assertEquals(99, writeIFs1.x);
79
+        assertEquals(99, writeIFs1.getValueOfx());
80 80
     }
81 81
     @Test
82 82
     public void TestFireControl()
83 83
     {
84 84
         WriteIFs writeIFs1 = new WriteIFs();
85
-        Object oo = new Object();
86
-        writeIFs1.tt_s = 1;
87
-        writeIFs1.fireplaceControl(oo);
88
-        assertEquals(213, writeIFs1.tt_s);
85
+        //Object oo = new Object();
86
+        writeIFs1.putValueOftts(1);
87
+        writeIFs1.fireplaceControl();
88
+        assertEquals(213, writeIFs1.getValueOftts());
89 89
     }
90 90
     @Test
91 91
     public void TestFireControl2()
92 92
     {
93 93
         WriteIFs writeIFs1 = new WriteIFs();
94
-        Object oo = new Object();
95
-        writeIFs1.oo1 = 65;
96
-        writeIFs1.tt_s = 1;
97
-        writeIFs1.fireplaceControl(oo);
98
-        assertEquals(213, writeIFs1.tt_s);
94
+        //Object oo = new Object();
95
+        writeIFs1.putValueOfoo1(65);
96
+        writeIFs1.putValueOftts(1);
97
+        writeIFs1.fireplaceControl();
98
+        assertEquals(213, writeIFs1.getValueOftts());
99 99
     }
100 100
     @Test
101 101
     public void TestFireControl3()
102 102
     {
103 103
         WriteIFs writeIFs1 = new WriteIFs();
104
-        Object oo = new Object();
105
-        writeIFs1.oo2 = 80;
106
-        writeIFs1.tt_s = 1;
107
-        writeIFs1.fireplaceControl(oo);
108
-        assertEquals(213, writeIFs1.tt_s);
104
+        //Object oo = new Object();
105
+        writeIFs1.putValueOfoo2(80);
106
+        writeIFs1.putValueOftts(1);
107
+        writeIFs1.fireplaceControl();
108
+        assertEquals(213, writeIFs1.getValueOftts());
109 109
     }
110 110
 
111 111
 }

+ 122
- 46
WriteLoops.java 파일 보기

@@ -20,7 +20,10 @@ public class WriteLoops {
20 20
 
21 21
         // Write a FOR loop that counts from 1 to 10.
22 22
             // calling
23
+            for (int i=1;i<=5;i++)
24
+            {
23 25
             w = w + 1;
26
+        }
24 27
             // each time through the loop
25 28
 
26 29
         // this will tell the test how many times the loop executed.
@@ -32,7 +35,10 @@ public class WriteLoops {
32 35
 
33 36
         // Write a FOR loop that counts from 1 to 10.
34 37
         // calling
38
+        for (int i=1;i<=10;i++)
39
+        {
35 40
         w = w + 1;
41
+    }
36 42
         // each time through the loop
37 43
         
38 44
         return w;
@@ -43,9 +49,11 @@ public class WriteLoops {
43 49
 
44 50
         // Write a FOR loop that makes 10 iterations, start at 21.
45 51
         // calling
52
+        for (int i=21;i<=31;i++)
53
+        {
46 54
         w = w + 1;
47 55
         // each time through the loop
48
-        
56
+    }
49 57
         return w;
50 58
     }
51 59
 
@@ -54,9 +62,11 @@ public class WriteLoops {
54 62
 
55 63
         // Write a FOR loop that counts down from 100 to 0.
56 64
         // calling
65
+        for(int i=100;i>0;i--)
66
+        {
57 67
         w = w + 1;
58 68
         // each time through the loop
59
-        
69
+    }
60 70
         return w;
61 71
     }
62 72
 
@@ -65,17 +75,22 @@ public class WriteLoops {
65 75
 
66 76
         // Write a FOR loop from 0 to 32 by 2s.
67 77
         // calling
78
+        for(int i=0;i>32;i+=2)
79
+        {
68 80
         w = w + 1;
81
+    }
69 82
         // each time through the loop
70 83
         return w;
71 84
     }
72 85
 
73 86
     public int countDownFrom5000() {
74 87
         int w = 0;
75
-
76 88
         // Write a FOR loop from 1 to less than 5001 by 11s.
77 89
         // calling
90
+        for(int i=5000;i>0;i-=11)
91
+        {
78 92
         w = w + 1;
93
+    }
79 94
         // each time through the loop
80 95
         
81 96
         return w;
@@ -87,7 +102,13 @@ public class WriteLoops {
87 102
         // Write a nested FOR loop(s), where one counts from
88 103
         // 0 to less than 20 and the inner one counts from 0 to 4
89 104
                 // calling
105
+                for(int i=0;i<20;i++)
106
+                {
107
+                    for(int j=0;j<=4;j++)
108
+                    {
90 109
                 w = w + 1;
110
+            }
111
+        }
91 112
                 // each time through the inner loop
92 113
 
93 114
         return w;
@@ -95,16 +116,19 @@ public class WriteLoops {
95 116
 
96 117
     public int helloZipCode() {
97 118
         int w = 0;
98
-
99 119
         // Write a FOR loop that counts from 5 to 105. Put an IF
100 120
         // statement inside the loop that checks the
101 121
         // loop index counter and if it’s greater than 51,
102 122
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103
-
104
-                // calling
105
-                w = w + 1;
106
-            // each time through the inner loop
107
-        
123
+        // calling
124
+        for (int i = 5; i <= 105; i++)
125
+        {
126
+        if (i>51)
127
+            System.out.println("Hello Zipcode");
128
+        else
129
+            w = w + 1;
130
+        }
131
+        // each time through the inner loop
108 132
         return w;
109 133
     }
110 134
 
@@ -131,15 +155,15 @@ public class WriteLoops {
131 155
     // After the loop is done, print “Honey, I’m Home!”
132 156
     public int driveHome() {
133 157
         int w = 0;
134
-
158
+        do {
159
+        driveSomeMore();
135 160
         // you need to use a .equals for two Strings.
136
-
137
-            // calling
138
-            w = w + 1;
139
-            // each time through the inner loop
140
-        
141
-
142
-            return w;
161
+        // calling
162
+        w = w + 1;
163
+        // each time through the inner loop
164
+        } while (gpsCurrentLocation() != "Home");
165
+        System.out.println("Honey, I'm Home!");
166
+        return w;
143 167
     }
144 168
 
145 169
     // Getting harder...
@@ -149,7 +173,7 @@ public class WriteLoops {
149 173
     // "runningScore"
150 174
     // and then sets “currentScore” to “gameNextScore()”
151 175
     public int checkGameScore() {
152
-        int w = 0;
176
+        int w = 1;
153 177
         int highestScore = 236;
154 178
         int currentScore = gameNextScore();
155 179
         int runningScore = 0;
@@ -157,7 +181,12 @@ public class WriteLoops {
157 181
         // do your while loop here
158 182
  
159 183
             // calling
160
-            w = w + 1;
184
+            while (runningScore <= highestScore)
185
+            {
186
+                runningScore = runningScore + currentScore;
187
+                w = w + 1;
188
+                currentScore = gameNextScore();
189
+            }
161 190
             // each time through the inner loop
162 191
         
163 192
         return w; // >= 3;
@@ -172,7 +201,13 @@ public class WriteLoops {
172 201
         int runningScore = 0;
173 202
 
174 203
         // do your while loop here
175
-
204
+        do
205
+        {
206
+            runningScore = runningScore + currentScore;
207
+            w = w + 1;
208
+            currentScore = gameNextScore();
209
+        }
210
+        while(runningScore <= highestScore);
176 211
             // calling
177 212
             w = w + 1;
178 213
             // each time through the inner loop
@@ -184,15 +219,23 @@ public class WriteLoops {
184 219
     // calls “waitFor(5)” After the loop, write an IF and check “serverIsRunning()”
185 220
     // is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
186 221
     // and also calls “tryServerRestart()”
187
-    public int checkServerStatus() {
222
+    public int checkServerStatus() 
223
+    {
188 224
         int w = 0;
189 225
         String adminPhoneNumber = "+1 202 456 1111";
190
-        
191
-
192
-        // calling
193
-        w = w + 1;
194
-        // each time through the inner loop
195
-        
226
+        boolean res = serverIsRunning();
227
+        while (res == true)
228
+        {
229
+            waitFor(5);
230
+        }
231
+        if (res != true)
232
+        {
233
+            // calling
234
+            sendEmergencyText("Help!", adminPhoneNumber);
235
+            tryServerRestart("Restart Server", adminPhoneNumber);
236
+            w = w + 1;
237
+            // each time through the inner loop
238
+        }
196 239
         return w;
197 240
     }
198 241
 
@@ -201,10 +244,14 @@ public class WriteLoops {
201 244
     // and if it is, add 7 to “i”
202 245
     public int loop50by7() {
203 246
         int w = 0;
204
-
205
-
206
-            // calling
247
+        int i = 7;
248
+        while(i<50)
249
+        {
250
+            i = i+7;
251
+        }
252
+        // calling
207 253
             w = w + 1;
254
+        
208 255
             // each time through the inner loop
209 256
         
210 257
         return w;
@@ -220,7 +267,8 @@ public class WriteLoops {
220 267
         int sumOfThrees = 0;
221 268
 
222 269
         // this is a so called Enhanced for loop
223
-        for (int index : threes_array) {
270
+        for (int index : threes_array) 
271
+        {
224 272
             sumOfThrees = sumOfThrees + threes_array[index];
225 273
             // calling
226 274
             w = w + 1;
@@ -235,18 +283,20 @@ public class WriteLoops {
235 283
     // Ponder this: can all FOR loops be rewritten as WHILE loops?
236 284
     // rewrite the loop inside of "foo()" as a standard for loop
237 285
     // with 'i' as its index variable.
238
-    public int rewriteFooAsFor() {
286
+    public int rewriteFooAsFor()
287
+    {
239 288
         int w = 0;
240 289
         int sumOfThrees = 0;
241
-
242
- 
243
-            // calling
290
+        int str = threes_array.length;
291
+        for (int i = 0; i<= str; i++)
292
+        {
293
+            sumOfThrees = sumOfThrees + threes_array[i];
244 294
             w = w + 1;
245
-            // each time through the inner loop
246
-        
295
+        }
296
+        // calling
297
+        // each time through the inner loop
247 298
         System.out.print("The Sum is ");
248 299
         System.out.println(sumOfThrees);
249
-
250 300
         return w;
251 301
     }
252 302
 
@@ -255,10 +305,17 @@ public class WriteLoops {
255 305
     public int rewriteFooAsWhile() {
256 306
         int w = 0;
257 307
         int sumOfThrees = 0;
258
-
308
+        int i = 0;
309
+        int arraylength = threes_array.length;
310
+        
311
+        while (i <= arraylength)
312
+        {
313
+            sumOfThrees = sumOfThrees + threes_array[i];
314
+            w = w + 1;
315
+        }
259 316
  
260 317
             // calling
261
-            w = w + 1;
318
+            
262 319
             // each time through the inner loop
263 320
         
264 321
         System.out.print("The Sum is ");
@@ -274,16 +331,25 @@ public class WriteLoops {
274 331
     // After loop, call
275 332
     // “sendJuniorBackToSchool()” with an argument that decribes the day junior goes
276 333
     // back.
277
-    public int manageYardAndJunior() {
334
+    public int manageYardAndJunior() 
335
+    {
278 336
         int w = 0;
279 337
         boolean onTime = true;
280
-
338
+        boolean yardNeedsMowed = true;
339
+        
281 340
         // ADD YOUR CODE here.
341
+        while (isSummer()) {
342
+            
343
+            if (yardNeedsMowed == true) {
344
+                yellAtJuniorToMowLawn();
345
+            }
346
+            w = w + 1;
347
+            sendJuniorBackToSchool("");
282 348
  
283 349
             // be sure to call
284
-            w = w + 1;
350
+            
285 351
             // each time inside the loop
286
-        
352
+        }
287 353
         return w;
288 354
     }
289 355
 
@@ -295,7 +361,11 @@ public class WriteLoops {
295 361
     public int tallyVote1() {
296 362
         int w = 0;
297 363
         int numberOfVotes = voteTallies.length;
298
-
364
+        for(int i =0;i<numberOfVotes;i++)
365
+        {
366
+            System.out.println(voteTallies[i]+",");
367
+        }
368
+       
299 369
  
300 370
             // calling
301 371
             w = w + 1;
@@ -310,7 +380,13 @@ public class WriteLoops {
310 380
     public int tallyVote2() {
311 381
         int w = 0;
312 382
         int numberOfVotes = voteTallies.length;
313
-
383
+        int i =0;
384
+        while(i<numberOfVotes)
385
+       
386
+        {
387
+            System.out.println(voteTallies[i]+",");
388
+            i++;
389
+        }
314 390
 
315 391
             // calling
316 392
             w = w + 1;

+ 14
- 14
package.bluej 파일 보기

@@ -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
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
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=83
13
+objectbench.width=444
14
+package.divider.horizontal=0.6005326231691078
15
+package.divider.vertical=0.8517298187808896
16
+package.editor.height=510
17
+package.editor.width=645
18
+package.editor.x=125
19
+package.editor.y=58
20
+package.frame.height=665
21
+package.frame.width=771
22 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true