Browse Source

completed

Jevit Tith 6 years ago
parent
commit
1fc7abe30d
4 changed files with 219 additions and 30 deletions
  1. 79
    9
      MainApplication.java
  2. 42
    0
      MainApplicationTest.java
  3. 69
    0
      ScientificOperations.java
  4. 29
    21
      package.bluej

+ 79
- 9
MainApplication.java View File

@@ -1,17 +1,87 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by leon on 2/9/18.
5 4
  */
5
+import java.util.Scanner;
6 6
 public class MainApplication {
7
-    public static void main(String[] args) {
8
-        Console.println("Welcome to my calculator!");
9
-        String s = Console.getStringInput("Enter a string");
10
-        Integer i = Console.getIntegerInput("Enter an integer");
11
-        Double d = Console.getDoubleInput("Enter a double.");
7
+  
8
+   
9
+      ScientificOperations sos=new ScientificOperations();
10
+      
12 11
 
13
-        Console.println("The user input %s as a string", s);
14
-        Console.println("The user input %s as a integer", i);
15
-        Console.println("The user input %s as a d", d);
12
+    public static void main(String[] args)
13
+    {
14
+        System.out.println("Enter first and second number:");
15
+        Scanner inp= new Scanner(System.in);
16
+        int num1,num2;
17
+        num1 = inp.nextInt();
18
+        num2 = inp.nextInt();
19
+        int ans;
20
+        System.out.println("Enter your selection: 1 for Addition, 2 for substraction 3 for Multiplication and 4 for division:");
21
+        int choose;
22
+        choose = inp.nextInt();
23
+        switch (choose){
24
+        case 1:
25
+            System.out.println(add( num1,num2));
26
+            break;
27
+        case 2:
28
+            System.out.println(sub( num1,num2));
29
+            break;      
30
+        case 3:
31
+            System.out.println(mult( num1,num2));
32
+            break;
33
+        case 4:
34
+            System.out.println(div( num1,num2));
35
+            break;
36
+            default:
37
+                System.out.println("Illigal Operation");
38
+         case 5:
39
+               System.out.println(ScientificOperations.Exponent(3,3));
40
+               break;
41
+         case 6:
42
+                System.out.println(ScientificOperations.Inverse(5));
43
+               break;
44
+          case 7:
45
+                System.out.println(ScientificOperations.ScientificSin(90));
46
+                break;  
47
+          case 8:
48
+                 System.out.println(ScientificOperations.ScientificCosin(90));
49
+                 break; 
50
+          case 9:
51
+                System.out.println(ScientificOperations.ScientificTan(90));
52
+                break; 
53
+           case 10:
54
+                 System.out.println(ScientificOperations.InverseCos(90));
55
+                 break;  
56
+           case 11:
57
+                System.out.println(ScientificOperations.InverseSin(180));
58
+                 break; 
59
+        }
60
+
61
+
62
+
63
+    }
64
+    public static int add(int x, int y)
65
+    {
66
+        int result = x + y;
67
+        return result;
16 68
     }
69
+    public static int sub(int x, int y)
70
+    {
71
+        int result = x-y;
72
+        return result;
73
+    }
74
+    public static int mult(int x, int y)
75
+    {
76
+        int result = x*y;
77
+        return result;
78
+    }
79
+    public static int div(int x, int y)
80
+    {
81
+        int result = x/y;
82
+        return result;
83
+    }
84
+
17 85
 }
86
+        
87
+    

+ 42
- 0
MainApplicationTest.java View File

@@ -0,0 +1,42 @@
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 MainApplicationTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class MainApplicationTest
15
+{
16
+    /**
17
+     * Default constructor for test class MainApplicationTest
18
+     */
19
+    public MainApplicationTest()
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
+}

+ 69
- 0
ScientificOperations.java View File

@@ -0,0 +1,69 @@
1
+
2
+/**
3
+ * Write a description of class ScientificOperations here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public  class ScientificOperations
9
+{
10
+    // instance variables - replace the example below with your own
11
+    private int x;
12
+
13
+    /**
14
+     * Constructor for objects of class ScientificOperations
15
+     */
16
+    public ScientificOperations()
17
+    {
18
+        // initialise instance variables
19
+        x = 0;
20
+    }
21
+    
22
+    public static double product(double a,double b)
23
+    { return a*b;
24
+    }
25
+     public  static double Exponent(double a,double b)
26
+    {
27
+        return Math.pow(a,b);
28
+        
29
+    }
30
+   public static double Inverse(int x)
31
+   { 
32
+       double val=(double)x;
33
+       return 1/val;
34
+    }
35
+    public  static double ScientificSin(int x)
36
+    { 
37
+        double val=Math.sin((double)x);
38
+        return val;
39
+        
40
+    }
41
+    public static double ScientificCosin(int x)
42
+    {
43
+        double val=Math.cos((double)x);
44
+        return val;
45
+    }
46
+    public static double ScientificTan(int x)
47
+    {
48
+        double val=Math.tan((double)x);
49
+        return val;
50
+    }
51
+    public static double InverseSin(int x)
52
+    {
53
+        double val=Math.asin((double)x);
54
+        return val;
55
+        
56
+    }
57
+    public static double InverseCos(int x)
58
+    {
59
+        double val=Math.acos((double)x);
60
+        return val;
61
+    }
62
+    public static double add(double x,double y)
63
+    {
64
+        return x+y;
65
+    }
66
+    public static double sub(double x,double y)
67
+    { return x-y;
68
+    }
69
+}

+ 29
- 21
package.bluej View File

@@ -1,23 +1,23 @@
1 1
 #BlueJ package file
2 2
 dependency1.from=MainApplication
3
-dependency1.to=Console
3
+dependency1.to=ScientificOperations
4 4
 dependency1.type=UsesDependency
5
-editor.fx.0.height=722
6
-editor.fx.0.width=800
7
-editor.fx.0.x=640
8
-editor.fx.0.y=23
9
-objectbench.height=214
5
+editor.fx.0.height=0
6
+editor.fx.0.width=0
7
+editor.fx.0.x=0
8
+editor.fx.0.y=0
9
+objectbench.height=198
10 10
 objectbench.width=595
11
-package.divider.horizontal=0.6
12
-package.divider.vertical=0.6847360912981455
13
-package.editor.height=473
11
+package.divider.horizontal=0.5993322203672788
12
+package.divider.vertical=0.685099846390169
13
+package.editor.height=439
14 14
 package.editor.width=493
15 15
 package.editor.x=35
16
-package.editor.y=60
17
-package.frame.height=759
16
+package.editor.y=23
17
+package.frame.height=709
18 18
 package.frame.width=619
19 19
 package.numDependencies=1
20
-package.numTargets=2
20
+package.numTargets=3
21 21
 package.showExtends=true
22 22
 package.showUses=true
23 23
 project.charset=UTF-8
@@ -27,16 +27,24 @@ readme.width=47
27 27
 readme.x=10
28 28
 readme.y=10
29 29
 target1.height=50
30
-target1.name=Console
30
+target1.name=MainApplicationTest
31 31
 target1.showInterface=false
32
-target1.type=ClassTarget
33
-target1.width=80
34
-target1.x=80
35
-target1.y=200
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=120
34
+target1.x=100
35
+target1.y=40
36 36
 target2.height=50
37
-target2.name=MainApplication
37
+target2.name=ScientificOperations
38 38
 target2.showInterface=false
39 39
 target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
42
-target2.y=70
40
+target2.width=150
41
+target2.x=100
42
+target2.y=190
43
+target3.association=MainApplicationTest
44
+target3.height=50
45
+target3.name=MainApplication
46
+target3.showInterface=false
47
+target3.type=ClassTarget
48
+target3.width=120
49
+target3.x=70
50
+target3.y=70