Browse Source

wrote code for thermostat method in writeIFs

Margaret Pierse 6 years ago
parent
commit
50a5e2a7f2
1 changed files with 38 additions and 27 deletions
  1. 38
    27
      WriteIFs.java

+ 38
- 27
WriteIFs.java View File

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