Quellcode durchsuchen

completed loops

jtith5 vor 6 Jahren
Ursprung
Commit
0d761f60f7
3 geänderte Dateien mit 79 neuen und 33 gelöschten Zeilen
  1. 12
    6
      WriteIFs.java
  2. 47
    7
      WriteLoops.java
  3. 20
    20
      package.bluej

+ 12
- 6
WriteIFs.java Datei anzeigen

@@ -11,17 +11,18 @@ public class WriteIFs
11 11
     public void playerDied(boolean player1) {
12 12
         // Write an IF statement that checks “player1.isAlive()” 
13 13
         // and if that’s false, calls “displayGameOver(player1)”
14
-     
14
+        if (player1.isAlive() == false) {
15
+        return displayGameOver(player1);
16
+        } else return null;
15 17
     }
16 18
     
17 19
     public String thermoSTAT(int room) {
18 20
         // Write an IF statement that checks the 
19 21
         // “temperature(room)” and if that check is less than 70, 
20 22
         // calls “heatOn()” else calls “coolOn()”
21
-
22
-
23
-        
24
-        return this.ss;
23
+        if (room < 70) {
24
+        return heatOn();
25
+        } else return coolOn();   
25 26
     }
26 27
 
27 28
     public void fireplaceControl(Object fireplace1) {
@@ -30,13 +31,18 @@ public class WriteIFs
30 31
         // AND 
31 32
         // “insideTemp()” is less than 62, 
32 33
         // calls “startAFire(fireplace1)”
34
+        if (outsideTemp() < 50 && insideTemp() < 62) {
35
+        return startAFire(fireplace1);
36
+        }
33 37
 
34 38
     }
35 39
 
36 40
     public void checkFuel(double fuelLevel) {
37 41
         // Write an IF statement that checks “fuelLevel” 
38 42
         // and if that check is less than 0.08, calls “refuel()”
39
-
43
+        if (fuelLevel < 0.08) {
44
+        return refuel();
45
+        }
40 46
     }
41 47
 
42 48
 

+ 47
- 7
WriteLoops.java Datei anzeigen

@@ -20,7 +20,9 @@ public class WriteLoops {
20 20
 
21 21
         // Write a FOR loop that counts from 1 to 10.
22 22
             // calling
23
-            w = w + 1;
23
+            for (int i =0;i<5;i++) {
24
+            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.
@@ -32,7 +34,9 @@ public class WriteLoops {
32 34
 
33 35
         // Write a FOR loop that counts from 1 to 10.
34 36
         // calling
37
+        for (int i =0; i<10;i++) {
35 38
         w = w + 1;
39
+        }
36 40
         // each time through the loop
37 41
         
38 42
         return w;
@@ -43,7 +47,10 @@ public class WriteLoops {
43 47
 
44 48
         // Write a FOR loop that makes 10 iterations, start at 21.
45 49
         // calling
50
+        for (int i = 21; i>10; i--) {
46 51
         w = w + 1;
52
+        }
53
+      
47 54
         // each time through the loop
48 55
         
49 56
         return w;
@@ -54,18 +61,23 @@ public class WriteLoops {
54 61
 
55 62
         // Write a FOR loop that counts down from 100 to 0.
56 63
         // calling
64
+        for (int i =100; i>0;i--) {
57 65
         w = w + 1;
66
+    }
58 67
         // each time through the loop
59 68
         
60 69
         return w;
61 70
     }
62 71
 
72
+
63 73
     public int byTwoTo32() {
64 74
         int w = 0;
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) {
68 79
         w = w + 1;
80
+        } */
69 81
         // each time through the loop
70 82
         return w;
71 83
     }
@@ -75,7 +87,9 @@ public class WriteLoops {
75 87
 
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){
78 91
         w = w + 1;
92
+    }
79 93
         // each time through the loop
80 94
         
81 95
         return w;
@@ -87,7 +101,11 @@ public class WriteLoops {
87 101
         // Write a nested FOR loop(s), where one counts from
88 102
         // 0 to less than 20 and the inner one counts from 0 to 4
89 103
                 // calling
90
-                w = w + 1;
104
+                for (int i = 0; i<20; i++){
105
+                for (int j = 0; j <= 4; j++){
106
+                w = w+1;
107
+                }
108
+                }
91 109
                 // each time through the inner loop
92 110
 
93 111
         return w;
@@ -102,7 +120,11 @@ public class WriteLoops {
102 120
         // prints “Hello Zipcode” instead of the statement w = w + 1;
103 121
 
104 122
                 // calling
105
-                w = w + 1;
123
+                for (int i = 5; i <105; i++){
124
+                if (i <= 51) {
125
+                w =w + 1;
126
+                } else System.out.println("Hello Zipcode");   
127
+                }
106 128
             // each time through the inner loop
107 129
         
108 130
         return w;
@@ -135,8 +157,12 @@ public class WriteLoops {
135 157
         // you need to use a .equals for two Strings.
136 158
 
137 159
             // calling
138
-            w = w + 1;
160
+           
139 161
             // each time through the inner loop
162
+            while (gpsCurrentLocation() != ("Home")) {
163
+                driveSomeMore();
164
+                w = w+1;
165
+            }
140 166
         
141 167
 
142 168
             return w;
@@ -157,7 +183,11 @@ public class WriteLoops {
157 183
         // do your while loop here
158 184
  
159 185
             // calling
160
-            w = w + 1;
186
+            while (runningScore <= highestScore) {
187
+            runningScore = runningScore + currentScore;     
188
+            w = w+1;
189
+            currentScore = gameNextScore();
190
+            }
161 191
             // each time through the inner loop
162 192
         
163 193
         return w; // >= 3;
@@ -172,7 +202,10 @@ public class WriteLoops {
172 202
         int runningScore = 0;
173 203
 
174 204
         // do your while loop here
175
-
205
+        do { runningScore = runningScore + currentScore;     
206
+            w = w+1;
207
+            currentScore = gameNextScore();
208
+        } while (runningScore < highestScore);
176 209
             // calling
177 210
             w = w + 1;
178 211
             // each time through the inner loop
@@ -187,10 +220,17 @@ public class WriteLoops {
187 220
     public int checkServerStatus() {
188 221
         int w = 0;
189 222
         String adminPhoneNumber = "+1 202 456 1111";
223
+        while (serverIsRunning() == true) {
224
+        waitFor(5);
225
+        w= w+1;
226
+        }
227
+        if (serverIsRunning() == false) {
228
+        sendEmergencyText("Help!", adminPhoneNumber);
190 229
         
230
+        }
191 231
 
192 232
         // calling
193
-        w = w + 1;
233
+        //w = w + 1;
194 234
         // each time through the inner loop
195 235
         
196 236
         return w;

+ 20
- 20
package.bluej Datei anzeigen

@@ -5,18 +5,18 @@ 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=1047
9
+editor.fx.0.width=974
10
+editor.fx.0.x=1926
11
+editor.fx.0.y=16
12
+objectbench.height=106
13
+objectbench.width=1225
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
15
+package.divider.vertical=0.8481182795698925
16
+package.editor.height=624
17
+package.editor.width=1135
18
+package.editor.x=2132
19
+package.editor.y=93
20 20
 package.frame.height=844
21 21
 package.frame.width=1265
22 22
 package.numDependencies=2
@@ -44,18 +44,18 @@ target2.type=ClassTarget
44 44
 target2.width=100
45 45
 target2.x=140
46 46
 target2.y=360
47
+target3.association=WriteIFsTest
47 48
 target3.height=110
48
-target3.name=WriteIFsTest
49
+target3.name=WriteIFs
49 50
 target3.showInterface=false
50
-target3.type=UnitTestTargetJunit4
51
+target3.type=ClassTarget
51 52
 target3.width=80
52
-target3.x=180
53
-target3.y=100
54
-target4.association=WriteIFsTest
53
+target3.x=150
54
+target3.y=130
55 55
 target4.height=110
56
-target4.name=WriteIFs
56
+target4.name=WriteIFsTest
57 57
 target4.showInterface=false
58
-target4.type=ClassTarget
58
+target4.type=UnitTestTargetJunit4
59 59
 target4.width=80
60
-target4.x=150
61
-target4.y=130
60
+target4.x=180
61
+target4.y=100