Parcourir la source

wrote code for thermostat method in writeIFs

Margaret Pierse il y a 6 ans
Parent
révision
50a5e2a7f2
1 fichiers modifiés avec 38 ajouts et 27 suppressions
  1. 38
    27
      WriteIFs.java

+ 38
- 27
WriteIFs.java Voir le fichier

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