浏览代码

Completed the lab & all test pass

William Brown 6 年前
父节点
当前提交
6d76c5631c
共有 5 个文件被更改,包括 23 次插入24 次删除
  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 查看文件

@@ -12,7 +12,17 @@ public class WriteIFs
12 12
    int tt_s;
13 13
    int oo1, oo2;
14 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 27
     public void playerDied(boolean player1) {
18 28
         // Write an IF statement that checks “player1.isAlive()” 
@@ -40,7 +50,7 @@ public class WriteIFs
40 50
         // AND 
41 51
         // “insideTemp()” is less than 62, 
42 52
         // calls “startAFire(fireplace1)”
43
-        if(outsideTemp() < 50 && insideTemp() < 62){
53
+        if(outsideTemp() < 50 || insideTemp() < 62){
44 54
             startAFire(fireplace1);
45 55
         }
46 56
     }
@@ -70,16 +80,6 @@ public class WriteIFs
70 80
 
71 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 84
     // associated routines
85 85
     public boolean isAlive(boolean p) {
@@ -94,7 +94,6 @@ public class WriteIFs
94 94
     private void coolOn() {
95 95
         this.ss = "cooling";
96 96
     }
97
- 
98 97
     private int insideTemp() {
99 98
         return oo1;
100 99
     }

+ 3
- 3
WriteIFsTest.java 查看文件

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

+ 2
- 2
WriteLoops.java 查看文件

@@ -70,8 +70,8 @@ public class WriteLoops {
70 70
 
71 71
         // Write a FOR loop from 0 to 32 by 2s.
72 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 76
         // each time through the loop
77 77
         return w;

+ 1
- 1
WriteLoopsTest.java 查看文件

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

+ 5
- 5
package.bluej 查看文件

@@ -6,19 +6,19 @@ dependency2.from=WriteIFsTest
6 6
 dependency2.to=WriteIFs
7 7
 dependency2.type=UsesDependency
8 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 11
 editor.fx.0.y=23
12 12
 objectbench.height=91
13
-objectbench.width=720
13
+objectbench.width=455
14 14
 package.divider.horizontal=0.6
15 15
 package.divider.vertical=0.8499234303215927
16 16
 package.editor.height=548
17
-package.editor.width=618
17
+package.editor.width=353
18 18
 package.editor.x=0
19 19
 package.editor.y=23
20 20
 package.frame.height=711
21
-package.frame.width=744
21
+package.frame.width=479
22 22
 package.numDependencies=2
23 23
 package.numTargets=4
24 24
 package.showExtends=true