Browse Source

First Saturday

Elliott Stansbury 6 years ago
parent
commit
ff6dd52779
5 changed files with 174 additions and 80 deletions
  1. 53
    31
      WriteIFs.java
  2. 1
    0
      WriteIFsTest.java
  3. 97
    34
      WriteLoops.java
  4. 8
    0
      WriteLoopsTest.java
  5. 15
    15
      package.bluej

+ 53
- 31
WriteIFs.java View File

7
  */
7
  */
8
 public class WriteIFs
8
 public class WriteIFs
9
 {
9
 {
10
- 
10
+    int x;
11
+    int tt_t;
12
+    int tt_s;
13
+    int oo1, oo2;
14
+    String ss;
15
+
11
     public void playerDied(boolean player1) {
16
     public void playerDied(boolean player1) {
12
         // Write an IF statement that checks “player1.isAlive()” 
17
         // Write an IF statement that checks “player1.isAlive()” 
13
         // and if that’s false, calls “displayGameOver(player1)”
18
         // and if that’s false, calls “displayGameOver(player1)”
14
-     
19
+        if(isAlive(player1)) {
20
+            
21
+        } else {
22
+          displayGameOver(player1);  
23
+        }
15
     }
24
     }
16
-    
17
     public String thermoSTAT(int room) {
25
     public String thermoSTAT(int room) {
18
         // Write an IF statement that checks the 
26
         // Write an IF statement that checks the 
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()”
29
+        if(room < 70){
30
+            heatOn();
31
+        } else {
32
+            coolOn();
33
+        }
21
 
34
 
22
-
23
-        
24
         return this.ss;
35
         return this.ss;
25
     }
36
     }
26
 
37
 
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);
47
+        
48
+    }
34
     }
49
     }
35
 
50
 
36
     public void checkFuel(double fuelLevel) {
51
     public void checkFuel(double fuelLevel) {
37
         // Write an IF statement that checks “fuelLevel” 
52
         // Write an IF statement that checks “fuelLevel” 
38
         // and if that check is less than 0.08, calls “refuel()”
53
         // and if that check is less than 0.08, calls “refuel()”
39
-
54
+        if(fuelLevel < 0.08){
55
+            refuel();
56
+        }
40
     }
57
     }
41
 
58
 
42
-
43
     
59
     
44
     /**
60
     /**
45
      *  Pay no attention to the code below this point.
61
      *  Pay no attention to the code below this point.
47
      * 
63
      * 
48
      * instance variables
64
      * instance variables
49
      * / 
65
      * / 
50
-   int x;
51
-   int tt_t;
52
-   int tt_s;
53
-   int oo1, oo2;
54
-   String ss;
55
-
56
-
57
-  /**
58
-   * Constructor for objects of class WriteIFs
59
-   */
60
-  public WriteIFs()
61
-  {
62
-      // initialise instance variables
63
-      x = 0;
64
-      tt_t = 0;
65
-      tt_s = 1;
66
-      ss = "";
67
-      oo1 = 61;
68
-      oo2 = 49;
69
-  }
66
+    int x;
67
+    int tt_t;
68
+    int tt_s;
69
+    int oo1, oo2;
70
+    String ss;
71
+
72
+    /**
73
+     * Constructor for objects of class WriteIFs
74
+     */
75
+    public WriteIFs()
76
+    {
77
+        // initialise instance variables
78
+        x = 0;
79
+        tt_t = 0;
80
+        tt_s = 1;
81
+        ss = "";
82
+        oo1 = 61;
83
+        oo2 = 49;
84
+    }
70
 
85
 
71
     // associated routines
86
     // associated routines
72
     public boolean isAlive(boolean p) {
87
     public boolean isAlive(boolean p) {
73
         return !p;
88
         return !p;
74
     }
89
     }
90
+
75
     private int tempurature(int t) {
91
     private int tempurature(int t) {
76
         return t+2;
92
         return t+2;
77
     }
93
     }
94
+
78
     private void heatOn() {
95
     private void heatOn() {
79
         this.ss = "heating";
96
         this.ss = "heating";
80
     }
97
     }
98
+
81
     private void coolOn() {
99
     private void coolOn() {
82
         this.ss = "cooling";
100
         this.ss = "cooling";
83
     }
101
     }
84
- 
85
-    private int insideTemp() {
102
+
103
+    public int insideTemp() {
86
         return oo1;
104
         return oo1;
87
     }
105
     }
88
-    private int outsideTemp() {
106
+
107
+    public int outsideTemp() {
89
         return oo2;
108
         return oo2;
90
     }
109
     }
110
+
91
     private void startAFire(Object o) {
111
     private void startAFire(Object o) {
92
         this.tt_s = 213;
112
         this.tt_s = 213;
93
     }
113
     }
114
+
94
     private void refuel() {
115
     private void refuel() {
95
         this.x = 99;
116
         this.x = 99;
96
     }
117
     }
118
+
97
     private void displayGameOver(boolean b) {
119
     private void displayGameOver(boolean b) {
98
         this.ss = "Game Over!";
120
         this.ss = "Game Over!";
99
     }
121
     }

+ 1
- 0
WriteIFsTest.java View File

13
  */
13
  */
14
 public class WriteIFsTest
14
 public class WriteIFsTest
15
 {
15
 {
16
+    
16
     private static final double _0_5 = 0.5;
17
     private static final double _0_5 = 0.5;
17
     private static final double _0_04 = 0.04;
18
     private static final double _0_04 = 0.04;
18
 
19
 

+ 97
- 34
WriteLoops.java View File

1
 import com.sun.org.apache.xpath.internal.SourceTree;
1
 import com.sun.org.apache.xpath.internal.SourceTree;
2
-
2
+import java.lang.String;
3
 import java.awt.SystemTray;
3
 import java.awt.SystemTray;
4
 import java.util.concurrent.ThreadLocalRandom;
4
 import java.util.concurrent.ThreadLocalRandom;
5
 import java.util.function.Supplier;
5
 import java.util.function.Supplier;
17
 
17
 
18
     public int oneToFive() {
18
     public int oneToFive() {
19
         int w = 0;
19
         int w = 0;
20
-
20
+        for(int i = 1; i <= 5;i++){
21
+            w++;
22
+        }
21
         // Write a FOR loop that counts from 1 to 10.
23
         // Write a FOR loop that counts from 1 to 10.
22
             // calling
24
             // calling
23
-            w = w + 1;
25
+         
24
             // each time through the loop
26
             // each time through the loop
25
 
27
 
26
         // this will tell the test how many times the loop executed.
28
         // this will tell the test how many times the loop executed.
29
 
31
 
30
     public int oneToTen() {
32
     public int oneToTen() {
31
         int w = 0;
33
         int w = 0;
32
-
34
+        for(int i = 1; i <= 10; i++){
35
+            w++;
36
+        }
33
         // Write a FOR loop that counts from 1 to 10.
37
         // Write a FOR loop that counts from 1 to 10.
34
         // calling
38
         // calling
35
-        w = w + 1;
39
+        
36
         // each time through the loop
40
         // each time through the loop
37
         
41
         
38
         return w;
42
         return w;
40
 
44
 
41
     public int startAtTwentyOne() {
45
     public int startAtTwentyOne() {
42
         int w = 0;
46
         int w = 0;
43
-
47
+        
48
+        for(int i = 21; i <= 31; i++){
49
+            w++;
50
+            
51
+        } 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
52
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
53
         // calling
46
-        w = w + 1;
54
+        
47
         // each time through the loop
55
         // each time through the loop
48
         
56
         
57
+        
58
+        
49
         return w;
59
         return w;
50
     }
60
     }
51
 
61
 
52
     public int countDown() {
62
     public int countDown() {
53
         int w = 0;
63
         int w = 0;
54
-
64
+        
65
+        for(int i = 100; i > 0; i--){
66
+            w++;
67
+        }
55
         // Write a FOR loop that counts down from 100 to 0.
68
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
69
         // calling
57
-        w = w + 1;
70
+        
58
         // each time through the loop
71
         // each time through the loop
59
         
72
         
60
         return w;
73
         return w;
62
 
75
 
63
     public int byTwoTo32() {
76
     public int byTwoTo32() {
64
         int w = 0;
77
         int w = 0;
65
-
66
-        // Write a FOR loop from 0 to 32 by 2s.
67
-        // calling
68
-        w = w + 1;
78
+        //for(int i = 2; i <= 32; i+=2){
79
+            //w++;
80
+        //}
81
+        
82
+        System.out.println(w);
69
         // each time through the loop
83
         // each time through the loop
70
         return w;
84
         return w;
71
     }
85
     }
72
-
86
+    
87
+    private int by2to32(){
88
+        int w = 0;
89
+        for(int i = 2; i <= 32; i+=2){
90
+           w++;
91
+        }
92
+       
93
+        return w;
94
+   }
95
+    
73
     public int countDownFrom5000() {
96
     public int countDownFrom5000() {
74
         int w = 0;
97
         int w = 0;
75
-
98
+        for(int i=1; i < 5001; i+=11){
99
+            w++;
100
+        }
76
         // Write a FOR loop from 1 to less than 5001 by 11s.
101
         // Write a FOR loop from 1 to less than 5001 by 11s.
77
         // calling
102
         // calling
78
-        w = w + 1;
79
-        // each time through the loop
80
         
103
         
104
+        // each time through the loop
105
+        System.out.println(w);
81
         return w;
106
         return w;
82
     }
107
     }
83
 
108
 
84
     public int nestedFors() {
109
     public int nestedFors() {
85
         int w = 0;
110
         int w = 0;
86
-
111
+        for(int i = 0; i < 20; i++){
112
+            for(int j = 0; j <= 4; j++){
113
+                w++;
114
+            }
115
+        }
87
         // Write a nested FOR loop(s), where one counts from
116
         // 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
117
         // 0 to less than 20 and the inner one counts from 0 to 4
89
                 // calling
118
                 // calling
90
-                w = w + 1;
119
+                
91
                 // each time through the inner loop
120
                 // each time through the inner loop
92
 
121
 
93
         return w;
122
         return w;
95
 
124
 
96
     public int helloZipCode() {
125
     public int helloZipCode() {
97
         int w = 0;
126
         int w = 0;
98
-
127
+        int counter = 0;
128
+        for(int i = 5; i < 105; i++){
129
+           
130
+        
131
+        if(i > 51){
132
+           System.out.println("Hello Zipcode");
133
+        } else {
134
+        w++;
135
+        }
136
+    }
137
+        
99
         // Write a FOR loop that counts from 5 to 105. Put an IF
138
         // Write a FOR loop that counts from 5 to 105. Put an IF
100
         // statement inside the loop that checks the
139
         // statement inside the loop that checks the
101
         // loop index counter and if it’s greater than 51,
140
         // loop index counter and if it’s greater than 51,
102
         // prints “Hello Zipcode” instead of the statement w = w + 1;
141
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103
 
142
 
104
                 // calling
143
                 // calling
105
-                w = w + 1;
144
+                
106
             // each time through the inner loop
145
             // each time through the inner loop
107
-        
146
+        System.out.println(w);
108
         return w;
147
         return w;
109
     }
148
     }
110
 
149
 
131
     // After the loop is done, print “Honey, I’m Home!”
170
     // After the loop is done, print “Honey, I’m Home!”
132
     public int driveHome() {
171
     public int driveHome() {
133
         int w = 0;
172
         int w = 0;
134
-
173
+        while(!gpsCurrentLocation().equals("Home")){
174
+            driveSomeMore();
175
+            w++;
176
+        } 
135
         // you need to use a .equals for two Strings.
177
         // you need to use a .equals for two Strings.
136
-
178
+        System.out.println("Honey, I'm Home!");    
137
             // calling
179
             // calling
138
-            w = w + 1;
180
+            
139
             // each time through the inner loop
181
             // each time through the inner loop
140
         
182
         
141
 
183
 
155
         int runningScore = 0;
197
         int runningScore = 0;
156
 
198
 
157
         // do your while loop here
199
         // do your while loop here
158
- 
200
+        while(runningScore < highestScore){
201
+            if(runningScore < highestScore){
202
+            runningScore += currentScore;
203
+            currentScore = gameNextScore();
204
+            w++;
205
+            }
206
+        
207
+        }
159
             // calling
208
             // calling
160
-            w = w + 1;
209
+        
161
             // each time through the inner loop
210
             // each time through the inner loop
162
         
211
         
163
         return w; // >= 3;
212
         return w; // >= 3;
172
         int runningScore = 0;
221
         int runningScore = 0;
173
 
222
 
174
         // do your while loop here
223
         // do your while loop here
175
-
224
+        do{
225
+            runningScore += currentScore;
226
+            currentScore = gameNextScore();
227
+            w++;
228
+        } while(runningScore < highestScore);
176
             // calling
229
             // calling
177
-            w = w + 1;
230
+            
231
+            System.out.println(w);
178
             // each time through the inner loop
232
             // each time through the inner loop
179
 
233
 
180
-        return w >= 3;
234
+        return w <= 3;
181
     }
235
     }
182
 
236
 
183
     // Write a WHILE loop that checks “serverIsRunning()” and if true
237
     // Write a WHILE loop that checks “serverIsRunning()” and if true
187
     public int checkServerStatus() {
241
     public int checkServerStatus() {
188
         int w = 0;
242
         int w = 0;
189
         String adminPhoneNumber = "+1 202 456 1111";
243
         String adminPhoneNumber = "+1 202 456 1111";
244
+        while(serverIsRunning()){
245
+            w++;
246
+            if(serverIsRunning() == true){
247
+                waitFor(5);
248
+            }else {
249
+            //sendEmergencyText("Help!", adminPhoneNumber());
250
+            //tryServerRestart();
251
+            }
252
+            
253
+        }
190
         
254
         
191
-
192
         // calling
255
         // calling
193
-        w = w + 1;
256
+       
194
         // each time through the inner loop
257
         // each time through the inner loop
195
         
258
         
196
         return w;
259
         return w;
386
             summer++;
449
             summer++;
387
             return false;
450
             return false;
388
         }
451
         }
389
-    private void sendEmergencyText(String mesg, String phone) {
452
+    public void sendEmergencyText(String mesg, String phone) {
390
     }
453
     }
391
 
454
 
392
-    private void tryServerRestart(String mesg, String phone) {
455
+    public void tryServerRestart(String mesg, String phone) {
393
     }
456
     }
394
 
457
 
395
     int serverStatus = 5;
458
     int serverStatus = 5;

+ 8
- 0
WriteLoopsTest.java View File

124
         WriteLoops writeLoo1 = new WriteLoops();
124
         WriteLoops writeLoo1 = new WriteLoops();
125
         assertEquals(3, writeLoo1.checkServerStatus());
125
         assertEquals(3, writeLoo1.checkServerStatus());
126
     }
126
     }
127
+
128
+    @Test
129
+    public void by2to32()
130
+    {
131
+        WriteLoops writeLoo2 = new WriteLoops();
132
+        assertEquals(16, writeLoo2.byTwoTo32());
133
+    }
127
 }
134
 }
128
 
135
 
129
 
136
 
136
 
143
 
137
 
144
 
138
 
145
 
146
+

+ 15
- 15
package.bluej View File

1
 #BlueJ package file
1
 #BlueJ package file
2
-dependency1.from=WriteLoopsTest
3
-dependency1.to=WriteLoops
2
+dependency1.from=WriteIFsTest
3
+dependency1.to=WriteIFs
4
 dependency1.type=UsesDependency
4
 dependency1.type=UsesDependency
5
-dependency2.from=WriteIFsTest
6
-dependency2.to=WriteIFs
5
+dependency2.from=WriteLoopsTest
6
+dependency2.to=WriteLoops
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
8
+editor.fx.0.height=709
9
 editor.fx.0.width=800
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
10
+editor.fx.0.x=-101
11
+editor.fx.0.y=-1152
12
+objectbench.height=91
13
+objectbench.width=1241
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
15
+package.divider.vertical=0.8366666666666667
16
+package.editor.height=495
17
+package.editor.width=1123
18
+package.editor.x=-395
19
+package.editor.y=-658
20
+package.frame.height=658
21
 package.frame.width=1265
21
 package.frame.width=1265
22
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4