Explorar el Código

First Saturday

Elliott Stansbury hace 6 años
padre
commit
ff6dd52779
Se han modificado 5 ficheros con 174 adiciones y 80 borrados
  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 Ver fichero

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

+ 1
- 0
WriteIFsTest.java Ver fichero

@@ -13,6 +13,7 @@ import org.junit.Test;
13 13
  */
14 14
 public class WriteIFsTest
15 15
 {
16
+    
16 17
     private static final double _0_5 = 0.5;
17 18
     private static final double _0_04 = 0.04;
18 19
 

+ 97
- 34
WriteLoops.java Ver fichero

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

+ 8
- 0
WriteLoopsTest.java Ver fichero

@@ -124,6 +124,13 @@ public class WriteLoopsTest
124 124
         WriteLoops writeLoo1 = new WriteLoops();
125 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,3 +143,4 @@ public class WriteLoopsTest
136 143
 
137 144
 
138 145
 
146
+

+ 15
- 15
package.bluej Ver fichero

@@ -1,23 +1,23 @@
1 1
 #BlueJ package file
2
-dependency1.from=WriteLoopsTest
3
-dependency1.to=WriteLoops
2
+dependency1.from=WriteIFsTest
3
+dependency1.to=WriteIFs
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=WriteIFsTest
6
-dependency2.to=WriteIFs
5
+dependency2.from=WriteLoopsTest
6
+dependency2.to=WriteLoops
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
8
+editor.fx.0.height=709
9 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 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 21
 package.frame.width=1265
22 22
 package.numDependencies=2
23 23
 package.numTargets=4