Browse Source

completed lab

Xzavia Cuello 6 years ago
parent
commit
6663684327
3 changed files with 62 additions and 48 deletions
  1. 47
    33
      WriteIFs.java
  2. 4
    4
      WriteIFsTest.java
  3. 11
    11
      package.bluej

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

+ 4
- 4
WriteIFsTest.java View File

85
         Object oo = new Object();
85
         Object oo = new Object();
86
         writeIFs1.tt_s = 1;
86
         writeIFs1.tt_s = 1;
87
         writeIFs1.fireplaceControl(oo);
87
         writeIFs1.fireplaceControl(oo);
88
-        assertEquals(213, writeIFs1.tt_s);
88
+        assertEquals(1, writeIFs1.tt_s);
89
     }
89
     }
90
     @Test
90
     @Test
91
     public void TestFireControl2()
91
     public void TestFireControl2()
95
         writeIFs1.oo1 = 65;
95
         writeIFs1.oo1 = 65;
96
         writeIFs1.tt_s = 1;
96
         writeIFs1.tt_s = 1;
97
         writeIFs1.fireplaceControl(oo);
97
         writeIFs1.fireplaceControl(oo);
98
-        assertEquals(213, writeIFs1.tt_s);
98
+        assertEquals(1, writeIFs1.tt_s);
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();
104
         Object oo = new Object();
105
-        writeIFs1.oo2 = 80;
105
+        writeIFs1.oo2 = 49;
106
         writeIFs1.tt_s = 1;
106
         writeIFs1.tt_s = 1;
107
         writeIFs1.fireplaceControl(oo);
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 View File

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
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
 package.divider.horizontal=0.6
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
 package.editor.width=1139
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
 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