Browse Source

Completed the lab & all test pass

William Brown 6 years ago
parent
commit
6d76c5631c
5 changed files with 23 additions and 24 deletions
  1. 12
    13
      WriteIFs.java
  2. 3
    3
      WriteIFsTest.java
  3. 2
    2
      WriteLoops.java
  4. 1
    1
      WriteLoopsTest.java
  5. 5
    5
      package.bluej

+ 12
- 13
WriteIFs.java View File

12
    int tt_s;
12
    int tt_s;
13
    int oo1, oo2;
13
    int oo1, oo2;
14
    String ss;
14
    String ss;
15
-
15
+   
16
+   public WriteIFs()
17
+  {
18
+      // initialise instance variables
19
+      x = 0;
20
+      tt_t = 0;
21
+      tt_s = 1;
22
+      ss = "";
23
+      oo1 = 61;
24
+      oo2 = 49;
25
+  }
16
  
26
  
17
     public void playerDied(boolean player1) {
27
     public void playerDied(boolean player1) {
18
         // Write an IF statement that checks “player1.isAlive()” 
28
         // Write an IF statement that checks “player1.isAlive()” 
40
         // AND 
50
         // AND 
41
         // “insideTemp()” is less than 62, 
51
         // “insideTemp()” is less than 62, 
42
         // calls “startAFire(fireplace1)”
52
         // calls “startAFire(fireplace1)”
43
-        if(outsideTemp() < 50 && insideTemp() < 62){
53
+        if(outsideTemp() < 50 || insideTemp() < 62){
44
             startAFire(fireplace1);
54
             startAFire(fireplace1);
45
         }
55
         }
46
     }
56
     }
70
 
80
 
71
    * Constructor for objects of class WriteIFs
81
    * Constructor for objects of class WriteIFs
72
    */
82
    */
73
-  public WriteIFs()
74
-  {
75
-      // initialise instance variables
76
-      x = 0;
77
-      tt_t = 0;
78
-      tt_s = 1;
79
-      ss = "";
80
-      oo1 = 61;
81
-      oo2 = 49;
82
-  }
83
 
83
 
84
     // associated routines
84
     // associated routines
85
     public boolean isAlive(boolean p) {
85
     public boolean isAlive(boolean p) {
94
     private void coolOn() {
94
     private void coolOn() {
95
         this.ss = "cooling";
95
         this.ss = "cooling";
96
     }
96
     }
97
- 
98
     private int insideTemp() {
97
     private int insideTemp() {
99
         return oo1;
98
         return oo1;
100
     }
99
     }

+ 3
- 3
WriteIFsTest.java View File

54
     {
54
     {
55
         WriteIFs writeIFs1 = new WriteIFs();
55
         WriteIFs writeIFs1 = new WriteIFs();
56
         writeIFs1.playerDied(true);
56
         writeIFs1.playerDied(true);
57
-        assertEquals("Game Over!", writeIFs1);
57
+        assertEquals("Game Over!", writeIFs1.ss);
58
     }
58
     }
59
 
59
 
60
 
60
 
75
     {
75
     {
76
         WriteIFs writeIFs1 = new WriteIFs();
76
         WriteIFs writeIFs1 = new WriteIFs();
77
         writeIFs1.checkFuel(_0_5);
77
         writeIFs1.checkFuel(_0_5);
78
-        assertEquals(0, writeIFs1);
78
+        assertEquals(0, writeIFs1.x);
79
     }
79
     }
80
     @Test
80
     @Test
81
     public void TestCheckFuel2()
81
     public void TestCheckFuel2()
82
     {
82
     {
83
         WriteIFs writeIFs1 = new WriteIFs();
83
         WriteIFs writeIFs1 = new WriteIFs();
84
         writeIFs1.checkFuel(_0_04);
84
         writeIFs1.checkFuel(_0_04);
85
-        assertEquals(99, writeIFs1);
85
+        assertEquals(99, writeIFs1.x);
86
     }
86
     }
87
     @Test
87
     @Test
88
     public void TestFireControl()
88
     public void TestFireControl()

+ 2
- 2
WriteLoops.java View File

70
 
70
 
71
         // Write a FOR loop from 0 to 32 by 2s.
71
         // Write a FOR loop from 0 to 32 by 2s.
72
         // calling
72
         // calling
73
-        for(int i = 0; i <= 17; i +=2){
74
-            w = w + 0;
73
+        for(int i = 0; i <= 32; i +=2){
74
+            w = w + 1;
75
         }
75
         }
76
         // each time through the loop
76
         // each time through the loop
77
         return w;
77
         return w;

+ 1
- 1
WriteLoopsTest.java View File

71
     public void Test2to32()
71
     public void Test2to32()
72
     {
72
     {
73
         WriteLoops writeLoo1 = new WriteLoops();
73
         WriteLoops writeLoo1 = new WriteLoops();
74
-        assertEquals(0, writeLoo1.byTwoTo32());
74
+        assertEquals(17, writeLoo1.byTwoTo32());
75
     }
75
     }
76
 
76
 
77
     @Test
77
     @Test

+ 5
- 5
package.bluej View File

6
 dependency2.to=WriteIFs
6
 dependency2.to=WriteIFs
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
 editor.fx.0.height=711
8
 editor.fx.0.height=711
9
-editor.fx.0.width=829
10
-editor.fx.0.x=451
9
+editor.fx.0.width=800
10
+editor.fx.0.x=480
11
 editor.fx.0.y=23
11
 editor.fx.0.y=23
12
 objectbench.height=91
12
 objectbench.height=91
13
-objectbench.width=720
13
+objectbench.width=455
14
 package.divider.horizontal=0.6
14
 package.divider.horizontal=0.6
15
 package.divider.vertical=0.8499234303215927
15
 package.divider.vertical=0.8499234303215927
16
 package.editor.height=548
16
 package.editor.height=548
17
-package.editor.width=618
17
+package.editor.width=353
18
 package.editor.x=0
18
 package.editor.x=0
19
 package.editor.y=23
19
 package.editor.y=23
20
 package.frame.height=711
20
 package.frame.height=711
21
-package.frame.width=744
21
+package.frame.width=479
22
 package.numDependencies=2
22
 package.numDependencies=2
23
 package.numTargets=4
23
 package.numTargets=4
24
 package.showExtends=true
24
 package.showExtends=true