ソースを参照

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
  */
7
  */
8
 public class WriteIFs
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
         // Write an IF statement that checks “player1.isAlive()” 
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
         // and if that’s false, calls “displayGameOver(player1)”
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
         // Write an IF statement that checks the 
65
         // Write an IF statement that checks the 
19
         // “temperature(room)” and if that check is less than 70, 
66
         // “temperature(room)” and if that check is less than 70, 
20
         // calls “heatOn()” else calls “coolOn()”
67
         // calls “heatOn()” else calls “coolOn()”
21
-
22
-
23
-        
24
         return this.ss;
68
         return this.ss;
25
     }
69
     }
26
 
70
 
27
-    public void fireplaceControl(Object fireplace1) {
71
+    public void fireplaceControl(Object fireplace1) 
72
+    {
28
         // Write an IF statement that checks 
73
         // Write an IF statement that checks 
29
         // “outsideTemp()” is less than 50 
74
         // “outsideTemp()” is less than 50 
30
         // AND 
75
         // AND 
31
         // “insideTemp()” is less than 62, 
76
         // “insideTemp()” is less than 62, 
32
         // calls “startAFire(fireplace1)”
77
         // calls “startAFire(fireplace1)”
33
-
78
+        if (outsideTemp()<50 && insideTemp()<62)
79
+        {
80
+            startAFire(fireplace1);
81
+        }
34
     }
82
     }
35
 
83
 
36
     public void checkFuel(double fuelLevel) {
84
     public void checkFuel(double fuelLevel) {
37
         // Write an IF statement that checks “fuelLevel” 
85
         // Write an IF statement that checks “fuelLevel” 
38
         // and if that check is less than 0.08, calls “refuel()”
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
   {
113
   {
62
       // initialise instance variables
114
       // initialise instance variables
63
       x = 0;
115
       x = 0;
64
-      tt_t = 0;
116
+      //tt_t = 0;
65
       tt_s = 1;
117
       tt_s = 1;
66
       ss = "";
118
       ss = "";
67
       oo1 = 61;
119
       oo1 = 61;
75
     private int tempurature(int t) {
127
     private int tempurature(int t) {
76
         return t+2;
128
         return t+2;
77
     }
129
     }
78
-    private void heatOn() {
130
+    private void heatOn() 
131
+    {
79
         this.ss = "heating";
132
         this.ss = "heating";
80
     }
133
     }
81
-    private void coolOn() {
134
+    private void coolOn() 
135
+    {
82
         this.ss = "cooling";
136
         this.ss = "cooling";
83
     }
137
     }
84
  
138
  

+ 17
- 17
WriteIFsTest.java ファイルの表示

48
     {
48
     {
49
         WriteIFs writeIFs1 = new WriteIFs();
49
         WriteIFs writeIFs1 = new WriteIFs();
50
         writeIFs1.playerDied(true);
50
         writeIFs1.playerDied(true);
51
-        assertEquals("Game Over!", writeIFs1.ss);
51
+        assertEquals("Game Over!", writeIFs1.getValueOfss());
52
     }
52
     }
53
 
53
 
54
 
54
 
69
     {
69
     {
70
         WriteIFs writeIFs1 = new WriteIFs();
70
         WriteIFs writeIFs1 = new WriteIFs();
71
         writeIFs1.checkFuel(_0_5);
71
         writeIFs1.checkFuel(_0_5);
72
-        assertEquals(0, writeIFs1.x);
72
+        assertEquals(0, writeIFs1.getValueOfx());
73
     }
73
     }
74
     @Test
74
     @Test
75
     public void TestCheckFuel2()
75
     public void TestCheckFuel2()
76
     {
76
     {
77
         WriteIFs writeIFs1 = new WriteIFs();
77
         WriteIFs writeIFs1 = new WriteIFs();
78
         writeIFs1.checkFuel(_0_04);
78
         writeIFs1.checkFuel(_0_04);
79
-        assertEquals(99, writeIFs1.x);
79
+        assertEquals(99, writeIFs1.getValueOfx());
80
     }
80
     }
81
     @Test
81
     @Test
82
     public void TestFireControl()
82
     public void TestFireControl()
83
     {
83
     {
84
         WriteIFs writeIFs1 = new WriteIFs();
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
     @Test
90
     @Test
91
     public void TestFireControl2()
91
     public void TestFireControl2()
92
     {
92
     {
93
         WriteIFs writeIFs1 = new WriteIFs();
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
     @Test
100
     @Test
101
     public void TestFireControl3()
101
     public void TestFireControl3()
102
     {
102
     {
103
         WriteIFs writeIFs1 = new WriteIFs();
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
 
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
+            for (int i=1;i<=5;i++)
24
+            {
23
             w = w + 1;
25
             w = w + 1;
26
+        }
24
             // each time through the loop
27
             // each time through the loop
25
 
28
 
26
         // this will tell the test how many times the loop executed.
29
         // this will tell the test how many times the loop executed.
32
 
35
 
33
         // Write a FOR loop that counts from 1 to 10.
36
         // Write a FOR loop that counts from 1 to 10.
34
         // calling
37
         // calling
38
+        for (int i=1;i<=10;i++)
39
+        {
35
         w = w + 1;
40
         w = w + 1;
41
+    }
36
         // each time through the loop
42
         // each time through the loop
37
         
43
         
38
         return w;
44
         return w;
43
 
49
 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
50
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
51
         // calling
52
+        for (int i=21;i<=31;i++)
53
+        {
46
         w = w + 1;
54
         w = w + 1;
47
         // each time through the loop
55
         // each time through the loop
48
-        
56
+    }
49
         return w;
57
         return w;
50
     }
58
     }
51
 
59
 
54
 
62
 
55
         // Write a FOR loop that counts down from 100 to 0.
63
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
64
         // calling
65
+        for(int i=100;i>0;i--)
66
+        {
57
         w = w + 1;
67
         w = w + 1;
58
         // each time through the loop
68
         // each time through the loop
59
-        
69
+    }
60
         return w;
70
         return w;
61
     }
71
     }
62
 
72
 
65
 
75
 
66
         // Write a FOR loop from 0 to 32 by 2s.
76
         // Write a FOR loop from 0 to 32 by 2s.
67
         // calling
77
         // calling
78
+        for(int i=0;i>32;i+=2)
79
+        {
68
         w = w + 1;
80
         w = w + 1;
81
+    }
69
         // each time through the loop
82
         // each time through the loop
70
         return w;
83
         return w;
71
     }
84
     }
72
 
85
 
73
     public int countDownFrom5000() {
86
     public int countDownFrom5000() {
74
         int w = 0;
87
         int w = 0;
75
-
76
         // Write a FOR loop from 1 to less than 5001 by 11s.
88
         // Write a FOR loop from 1 to less than 5001 by 11s.
77
         // calling
89
         // calling
90
+        for(int i=5000;i>0;i-=11)
91
+        {
78
         w = w + 1;
92
         w = w + 1;
93
+    }
79
         // each time through the loop
94
         // each time through the loop
80
         
95
         
81
         return w;
96
         return w;
87
         // Write a nested FOR loop(s), where one counts from
102
         // 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
103
         // 0 to less than 20 and the inner one counts from 0 to 4
89
                 // calling
104
                 // calling
105
+                for(int i=0;i<20;i++)
106
+                {
107
+                    for(int j=0;j<=4;j++)
108
+                    {
90
                 w = w + 1;
109
                 w = w + 1;
110
+            }
111
+        }
91
                 // each time through the inner loop
112
                 // each time through the inner loop
92
 
113
 
93
         return w;
114
         return w;
95
 
116
 
96
     public int helloZipCode() {
117
     public int helloZipCode() {
97
         int w = 0;
118
         int w = 0;
98
-
99
         // Write a FOR loop that counts from 5 to 105. Put an IF
119
         // Write a FOR loop that counts from 5 to 105. Put an IF
100
         // statement inside the loop that checks the
120
         // statement inside the loop that checks the
101
         // loop index counter and if it’s greater than 51,
121
         // loop index counter and if it’s greater than 51,
102
         // prints “Hello Zipcode” instead of the statement w = w + 1;
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
         return w;
132
         return w;
109
     }
133
     }
110
 
134
 
131
     // After the loop is done, print “Honey, I’m Home!”
155
     // After the loop is done, print “Honey, I’m Home!”
132
     public int driveHome() {
156
     public int driveHome() {
133
         int w = 0;
157
         int w = 0;
134
-
158
+        do {
159
+        driveSomeMore();
135
         // you need to use a .equals for two Strings.
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
     // Getting harder...
169
     // Getting harder...
149
     // "runningScore"
173
     // "runningScore"
150
     // and then sets “currentScore” to “gameNextScore()”
174
     // and then sets “currentScore” to “gameNextScore()”
151
     public int checkGameScore() {
175
     public int checkGameScore() {
152
-        int w = 0;
176
+        int w = 1;
153
         int highestScore = 236;
177
         int highestScore = 236;
154
         int currentScore = gameNextScore();
178
         int currentScore = gameNextScore();
155
         int runningScore = 0;
179
         int runningScore = 0;
157
         // do your while loop here
181
         // do your while loop here
158
  
182
  
159
             // calling
183
             // calling
160
-            w = w + 1;
184
+            while (runningScore <= highestScore)
185
+            {
186
+                runningScore = runningScore + currentScore;
187
+                w = w + 1;
188
+                currentScore = gameNextScore();
189
+            }
161
             // each time through the inner loop
190
             // each time through the inner loop
162
         
191
         
163
         return w; // >= 3;
192
         return w; // >= 3;
172
         int runningScore = 0;
201
         int runningScore = 0;
173
 
202
 
174
         // do your while loop here
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
             // calling
211
             // calling
177
             w = w + 1;
212
             w = w + 1;
178
             // each time through the inner loop
213
             // each time through the inner loop
184
     // calls “waitFor(5)” After the loop, write an IF and check “serverIsRunning()”
219
     // calls “waitFor(5)” After the loop, write an IF and check “serverIsRunning()”
185
     // is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
220
     // is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
186
     // and also calls “tryServerRestart()”
221
     // and also calls “tryServerRestart()”
187
-    public int checkServerStatus() {
222
+    public int checkServerStatus() 
223
+    {
188
         int w = 0;
224
         int w = 0;
189
         String adminPhoneNumber = "+1 202 456 1111";
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
         return w;
239
         return w;
197
     }
240
     }
198
 
241
 
201
     // and if it is, add 7 to “i”
244
     // and if it is, add 7 to “i”
202
     public int loop50by7() {
245
     public int loop50by7() {
203
         int w = 0;
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
             w = w + 1;
253
             w = w + 1;
254
+        
208
             // each time through the inner loop
255
             // each time through the inner loop
209
         
256
         
210
         return w;
257
         return w;
220
         int sumOfThrees = 0;
267
         int sumOfThrees = 0;
221
 
268
 
222
         // this is a so called Enhanced for loop
269
         // this is a so called Enhanced for loop
223
-        for (int index : threes_array) {
270
+        for (int index : threes_array) 
271
+        {
224
             sumOfThrees = sumOfThrees + threes_array[index];
272
             sumOfThrees = sumOfThrees + threes_array[index];
225
             // calling
273
             // calling
226
             w = w + 1;
274
             w = w + 1;
235
     // Ponder this: can all FOR loops be rewritten as WHILE loops?
283
     // Ponder this: can all FOR loops be rewritten as WHILE loops?
236
     // rewrite the loop inside of "foo()" as a standard for loop
284
     // rewrite the loop inside of "foo()" as a standard for loop
237
     // with 'i' as its index variable.
285
     // with 'i' as its index variable.
238
-    public int rewriteFooAsFor() {
286
+    public int rewriteFooAsFor()
287
+    {
239
         int w = 0;
288
         int w = 0;
240
         int sumOfThrees = 0;
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
             w = w + 1;
294
             w = w + 1;
245
-            // each time through the inner loop
246
-        
295
+        }
296
+        // calling
297
+        // each time through the inner loop
247
         System.out.print("The Sum is ");
298
         System.out.print("The Sum is ");
248
         System.out.println(sumOfThrees);
299
         System.out.println(sumOfThrees);
249
-
250
         return w;
300
         return w;
251
     }
301
     }
252
 
302
 
255
     public int rewriteFooAsWhile() {
305
     public int rewriteFooAsWhile() {
256
         int w = 0;
306
         int w = 0;
257
         int sumOfThrees = 0;
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
             // calling
317
             // calling
261
-            w = w + 1;
318
+            
262
             // each time through the inner loop
319
             // each time through the inner loop
263
         
320
         
264
         System.out.print("The Sum is ");
321
         System.out.print("The Sum is ");
274
     // After loop, call
331
     // After loop, call
275
     // “sendJuniorBackToSchool()” with an argument that decribes the day junior goes
332
     // “sendJuniorBackToSchool()” with an argument that decribes the day junior goes
276
     // back.
333
     // back.
277
-    public int manageYardAndJunior() {
334
+    public int manageYardAndJunior() 
335
+    {
278
         int w = 0;
336
         int w = 0;
279
         boolean onTime = true;
337
         boolean onTime = true;
280
-
338
+        boolean yardNeedsMowed = true;
339
+        
281
         // ADD YOUR CODE here.
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
             // be sure to call
349
             // be sure to call
284
-            w = w + 1;
350
+            
285
             // each time inside the loop
351
             // each time inside the loop
286
-        
352
+        }
287
         return w;
353
         return w;
288
     }
354
     }
289
 
355
 
295
     public int tallyVote1() {
361
     public int tallyVote1() {
296
         int w = 0;
362
         int w = 0;
297
         int numberOfVotes = voteTallies.length;
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
             // calling
370
             // calling
301
             w = w + 1;
371
             w = w + 1;
310
     public int tallyVote2() {
380
     public int tallyVote2() {
311
         int w = 0;
381
         int w = 0;
312
         int numberOfVotes = voteTallies.length;
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
             // calling
391
             // calling
316
             w = w + 1;
392
             w = w + 1;

+ 14
- 14
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
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
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4
24
 package.showExtends=true
24
 package.showExtends=true