Kaynağa Gözat

completed lab

Xzavia Cuello 6 yıl önce
ebeveyn
işleme
6663684327
3 değiştirilmiş dosya ile 62 ekleme ve 48 silme
  1. 47
    33
      WriteIFs.java
  2. 4
    4
      WriteIFsTest.java
  3. 11
    11
      package.bluej

+ 47
- 33
WriteIFs.java Dosyayı Görüntüle

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

+ 4
- 4
WriteIFsTest.java Dosyayı Görüntüle

@@ -85,7 +85,7 @@ public class WriteIFsTest
85 85
         Object oo = new Object();
86 86
         writeIFs1.tt_s = 1;
87 87
         writeIFs1.fireplaceControl(oo);
88
-        assertEquals(213, writeIFs1.tt_s);
88
+        assertEquals(1, writeIFs1.tt_s);
89 89
     }
90 90
     @Test
91 91
     public void TestFireControl2()
@@ -95,17 +95,17 @@ public class WriteIFsTest
95 95
         writeIFs1.oo1 = 65;
96 96
         writeIFs1.tt_s = 1;
97 97
         writeIFs1.fireplaceControl(oo);
98
-        assertEquals(213, writeIFs1.tt_s);
98
+        assertEquals(1, writeIFs1.tt_s);
99 99
     }
100 100
     @Test
101 101
     public void TestFireControl3()
102 102
     {
103 103
         WriteIFs writeIFs1 = new WriteIFs();
104 104
         Object oo = new Object();
105
-        writeIFs1.oo2 = 80;
105
+        writeIFs1.oo2 = 49;
106 106
         writeIFs1.tt_s = 1;
107 107
         writeIFs1.fireplaceControl(oo);
108
-        assertEquals(213, writeIFs1.tt_s);
108
+        assertEquals(1, writeIFs1.tt_s);
109 109
     }
110 110
 
111 111
 }

+ 11
- 11
package.bluej Dosyayı Görüntüle

@@ -5,19 +5,19 @@ 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=716
9
+editor.fx.0.width=1029
10
+editor.fx.0.x=136
11
+editor.fx.0.y=-860
12
+objectbench.height=92
13
+objectbench.width=1241
14 14
 package.divider.horizontal=0.6
15
-package.divider.vertical=0.8625954198473282
16
-package.editor.height=671
15
+package.divider.vertical=0.8490853658536586
16
+package.editor.height=550
17 17
 package.editor.width=1139
18
-package.editor.x=112
19
-package.editor.y=89
20
-package.frame.height=844
18
+package.editor.x=15
19
+package.editor.y=23
20
+package.frame.height=714
21 21
 package.frame.width=1265
22 22
 package.numDependencies=2
23 23
 package.numTargets=4