瀏覽代碼

fixed merge

Lauren Green 6 年之前
父節點
當前提交
bd9cb08325
共有 6 個文件被更改,包括 100 次插入8 次删除
  1. 3
    1
      Console.java
  2. 9
    1
      RealAdvanced.java
  3. 8
    0
      RealAdvancedTest.java
  4. 1
    1
      SwitchDisplay.java
  5. 74
    0
      SwitchDisplayTest.java
  6. 5
    5
      package.bluej

+ 3
- 1
Console.java 查看文件

@@ -143,8 +143,10 @@ public class Console {
143 143
                     advAnswer = advCalc.absoluteValue(advInput1);
144 144
                 }else if (mode.equals("6")){
145 145
                     advAnswer = advCalc.sqrt(advInput1);
146
+                }else if (mode.equals("7")){
147
+                    advAnswer = advCalc.factorial(advInput1);
146 148
 
147
-                }else if (mode.equals("7")) {
149
+                }else if (mode.equals("8")) {
148 150
                     break;
149 151
                 }else{
150 152
                     Console.println("Invalid input");

+ 9
- 1
RealAdvanced.java 查看文件

@@ -20,7 +20,8 @@ public class RealAdvanced
20 20
             "4: Switch Sign of x" + "\n"+
21 21
             "5: Absolute Value of x" + "\n"+
22 22
             "6: Square Root of x" + "\n"+
23
-            "7: Return to Main Menu");
23
+            "7: Factorial x!"+"\n"+
24
+            "8: Return to Main Menu");
24 25
 
25 26
     }
26 27
     // method to find x^2
@@ -46,4 +47,11 @@ public class RealAdvanced
46 47
 public double sqrt(double x){
47 48
     return Math.sqrt(x);
48 49
 }
50
+public double factorial(double x){
51
+    double answer = 1;
52
+    for (double i = x; i >0; i--){
53
+        answer = answer * i;
54
+    }
55
+    return answer;
56
+}
49 57
 }

+ 8
- 0
RealAdvancedTest.java 查看文件

@@ -81,6 +81,13 @@ public class RealAdvancedTest
81 81
         RealAdvanced realAdva1 = new RealAdvanced();
82 82
         assertEquals(5.0, realAdva1.sqrt(25), 0.1);
83 83
     }
84
+
85
+    @Test
86
+    public void factorialTest()
87
+    {
88
+        RealAdvanced realAdva1 = new RealAdvanced();
89
+        assertEquals(120.0, realAdva1.factorial(5), 0.1);
90
+    }
84 91
 }
85 92
 
86 93
 
@@ -88,3 +95,4 @@ public class RealAdvancedTest
88 95
 
89 96
 
90 97
 
98
+

+ 1
- 1
SwitchDisplay.java 查看文件

@@ -59,7 +59,7 @@ public class SwitchDisplay
59 59
     
60 60
     public String toDecimal(int userInput) {
61 61
         
62
-        return Integer.toBinaryString((int)userInput);
62
+        return Integer.toString(userInput);
63 63
         
64 64
     }
65 65
     

+ 74
- 0
SwitchDisplayTest.java 查看文件

@@ -0,0 +1,74 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class SwitchDisplayTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class SwitchDisplayTest
15
+{
16
+    /**
17
+     * Default constructor for test class SwitchDisplayTest
18
+     */
19
+    public SwitchDisplayTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+
43
+    @Test
44
+    public void toBinary()
45
+    {
46
+        SwitchDisplay switchDi1 = new SwitchDisplay();
47
+        assertEquals("101101", switchDi1.toBinary(45));
48
+    }
49
+
50
+    @Test
51
+    public void toOctal()
52
+    {
53
+        SwitchDisplay switchDi1 = new SwitchDisplay();
54
+        assertEquals("55", switchDi1.toOctal(45));
55
+    }
56
+
57
+    @Test
58
+    public void toHexa()
59
+    {
60
+        SwitchDisplay switchDi1 = new SwitchDisplay();
61
+        assertEquals("2d", switchDi1.toHexa(45));
62
+    }
63
+
64
+    @Test
65
+    public void toDecimal()
66
+    {
67
+        SwitchDisplay switchDi1 = new SwitchDisplay();
68
+        assertEquals("45", switchDi1.toDecimal(45));
69
+    }
70
+}
71
+
72
+
73
+
74
+

+ 5
- 5
package.bluej 查看文件

@@ -18,7 +18,7 @@ dependency14.from=Console
18 18
 dependency14.to=SwitchDisplay
19 19
 dependency14.type=UsesDependency
20 20
 dependency15.from=Console
21
-dependency15.to=Trig
21
+dependency15.to=SwitchDisplay
22 22
 dependency15.type=UsesDependency
23 23
 dependency16.from=Trig
24 24
 dependency16.to=Console
@@ -60,12 +60,12 @@ editor.fx.0.y=0
60 60
 objectbench.height=214
61 61
 objectbench.width=595
62 62
 package.divider.horizontal=0.6
63
-package.divider.vertical=0.6847360912981455
64
-package.editor.height=473
63
+package.divider.vertical=0.685099846390169
64
+package.editor.height=439
65 65
 package.editor.width=493
66 66
 package.editor.x=35
67
-package.editor.y=59
68
-package.frame.height=759
67
+package.editor.y=23
68
+package.frame.height=709
69 69
 package.frame.width=619
70 70
 package.numDependencies=18
71 71
 package.numTargets=12