浏览代码

added square root

父节点
当前提交
992c2ddccf
共有 4 个文件被更改,包括 26 次插入13 次删除
  1. 3
    1
      Console.java
  2. 5
    2
      RealAdvanced.java
  3. 8
    0
      RealAdvancedTest.java
  4. 10
    10
      package.bluej

+ 3
- 1
Console.java 查看文件

@@ -98,8 +98,10 @@ public class Console {
98 98
                     advAnswer = advCalc.opposite(advInput1);
99 99
                 }else if (mode.equals("5")){
100 100
                     advAnswer = advCalc.absoluteValue(advInput1);
101
+                }else if (mode.equals("6")){
102
+                    advAnswer = advCalc.sqrt(advInput1);
101 103
 
102
-                }else if (mode.equals("6")) {
104
+                }else if (mode.equals("7")) {
103 105
                     break;
104 106
                 }else{
105 107
                     Console.println("Invalid input");

+ 5
- 2
RealAdvanced.java 查看文件

@@ -19,7 +19,8 @@ public class RealAdvanced
19 19
             "3: 1/x" + "\n"+
20 20
             "4: Switch Sign of x" + "\n"+
21 21
             "5: Absolute Value of x" + "\n"+
22
-            "6: Return to Main Menu");
22
+            "6: Square Root of x" + "\n"+
23
+            "7: Return to Main Menu");
23 24
 
24 25
     }
25 26
     // method to find x^2
@@ -42,5 +43,7 @@ public class RealAdvanced
42 43
     public double absoluteValue(double x){
43 44
         return Math.abs(x);
44 45
     }
45
-
46
+public double sqrt(double x){
47
+    return Math.sqrt(x);
48
+}
46 49
 }

+ 8
- 0
RealAdvancedTest.java 查看文件

@@ -74,9 +74,17 @@ public class RealAdvancedTest
74 74
         RealAdvanced realAdva1 = new RealAdvanced();
75 75
         assertEquals(4.0, realAdva1.absoluteValue(-4), 0.1);
76 76
     }
77
+
78
+    @Test
79
+    public void squareRootTest()
80
+    {
81
+        RealAdvanced realAdva1 = new RealAdvanced();
82
+        assertEquals(5.0, realAdva1.sqrt(25), 0.1);
83
+    }
77 84
 }
78 85
 
79 86
 
80 87
 
81 88
 
82 89
 
90
+

+ 10
- 10
package.bluej 查看文件

@@ -3,25 +3,25 @@ dependency1.from=Basic
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5 5
 dependency10.from=Console
6
-dependency10.to=MainMenu
6
+dependency10.to=Basic
7 7
 dependency10.type=UsesDependency
8 8
 dependency11.from=Console
9
-dependency11.to=Basic
9
+dependency11.to=RealAdvanced
10 10
 dependency11.type=UsesDependency
11 11
 dependency12.from=Console
12
-dependency12.to=RealAdvanced
12
+dependency12.to=SciCalc
13 13
 dependency12.type=UsesDependency
14 14
 dependency13.from=Console
15
-dependency13.to=SciCalc
15
+dependency13.to=MemoryFunc
16 16
 dependency13.type=UsesDependency
17 17
 dependency14.from=Console
18
-dependency14.to=MemoryFunc
18
+dependency14.to=SwitchDisplay
19 19
 dependency14.type=UsesDependency
20 20
 dependency15.from=Console
21
-dependency15.to=SwitchDisplay
21
+dependency15.to=Trig
22 22
 dependency15.type=UsesDependency
23
-dependency16.from=Console
24
-dependency16.to=Trig
23
+dependency16.from=RealAdvancedTest
24
+dependency16.to=RealAdvanced
25 25
 dependency16.type=UsesDependency
26 26
 dependency2.from=SciCalc
27 27
 dependency2.to=Console
@@ -44,8 +44,8 @@ dependency7.type=UsesDependency
44 44
 dependency8.from=RealAdvanced
45 45
 dependency8.to=Console
46 46
 dependency8.type=UsesDependency
47
-dependency9.from=RealAdvancedTest
48
-dependency9.to=RealAdvanced
47
+dependency9.from=Console
48
+dependency9.to=MainMenu
49 49
 dependency9.type=UsesDependency
50 50
 editor.fx.0.height=709
51 51
 editor.fx.0.width=1215