Bladeren bron

Merge branch 'master' of WJB3003/ZCW-MacroLabs-OOP-ScientificCalculator into master

William Brown 6 jaren geleden
bovenliggende
commit
7148ab596b
6 gewijzigde bestanden met toevoegingen van 157 en 80 verwijderingen
  1. 31
    35
      Console.java
  2. 9
    1
      MainApplication.java
  3. 41
    0
      Trigonometry.java
  4. 31
    11
      opSwitch.java
  5. 36
    30
      package.bluej
  6. 9
    3
      simpleOp.java

+ 31
- 35
Console.java Bestand weergeven

@@ -4,29 +4,29 @@ import java.lang.*;
4 4
  * Created by leon on 2/9/18.
5 5
  */
6 6
 public class Console {
7
-
7
+    //GIVEN TO US 
8 8
     public static void print(String output, Object... args) {
9 9
         System.out.printf(output, args);
10 10
     }
11
-
11
+    //GIVEN TO US
12 12
     public static void println(String output, Object... args) {
13 13
         print(output + "\n", args);
14 14
     }
15
-    
15
+    //GIVEN TO US
16 16
     public static String getStringInput(String prompt) {
17 17
         Scanner scanner = new Scanner(System.in);
18 18
         println(prompt);
19 19
         String userInput = scanner.nextLine();
20 20
         return userInput;
21 21
     }
22
-
22
+    //GIVEN TO US
23 23
     public static Integer  getIntInput(String prompt) {
24 24
         Scanner scanner = new Scanner(System.in);
25 25
         println(prompt);
26 26
         int userInput = scanner.nextInt();
27 27
         return userInput;
28 28
     }
29
-
29
+    //GIVEN TO US
30 30
     public static Double getDoubleInput(String prompt) {
31 31
         Scanner scanner = new Scanner(System.in);
32 32
         println(prompt);
@@ -40,22 +40,18 @@ public class Console {
40 40
             //return display;
41 41
     }
42 42
     
43
-    public static void clear(){
44
-        //CLEARS SCREEN / SET TO ZERO ??
45
-    }
46
-    
47
-    public static double getInput(String numberString){
48
-        //GETS INPUT FROM PERSON ( X )
49
-            //String numberString = getStringInput("Please choose a number.");
50
-            quit(numberString);
51
-        try{
52
-            double number1 = Double.parseDouble(numberString);
53
-            //System.out.println(number1);
54
-            return number1;
55
-        }catch(Exception e){
56
-            return getInput(numberString);
57
-        }
58
-    }
43
+    // public static double getInput(String numberString){
44
+        // //GETS INPUT FROM PERSON ( X )
45
+            // //String numberString = getStringInput("Please choose a number.");
46
+            // quit(numberString);
47
+        // try{
48
+            // double number1 = Double.parseDouble(numberString);
49
+            // //System.out.println(number1);
50
+            // return number1;
51
+        // }catch(Exception e){
52
+            // return getInput(numberString);
53
+        // }
54
+    // }
59 55
     /*
60 56
     public static double invert(double number){
61 57
         //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
@@ -69,17 +65,17 @@ public class Console {
69 65
     }
70 66
     */
71 67
     public static double getNumber(String numberString){
72
-        //GETS INPUT FROM PERSON ( Y )
73
-            //System.out.println(first + " " + op);
74
-            //String numberString = getStringInput("Please choose a number.");
75
-            quit(numberString);
76
-        try{
77
-            double number2 = Double.parseDouble(numberString);
78
-            //System.out.println(number2);
79
-            return number2;
80
-        }catch(Exception e){
81
-            return getNumber(numberString);
82
-        }
68
+            if(numberString.equals("quit") || numberString.equals("reset") || numberString.equals("clear")){
69
+                quit(numberString);
70
+                simpleOp.currentNumber = 0;
71
+            }else if(numberString.equals("pi")){
72
+                simpleOp.currentNumber = Math.PI;
73
+            }else if(numberString.equals("e")){
74
+                simpleOp.currentNumber = Math.E;
75
+            }else{
76
+                simpleOp.currentNumber = Double.parseDouble(numberString);
77
+            }
78
+            return simpleOp.currentNumber;
83 79
     }
84 80
     
85 81
     public static String getOp(){
@@ -96,14 +92,14 @@ public class Console {
96 92
     }
97 93
     
98 94
     public static void quit(String answer){
99
-        if(answer.equals("quit") || answer.equals("exit")){
95
+        if(answer.equals("quit")){
100 96
             System.exit(0);
101 97
         } else if(answer.equals("clear")) {
102 98
             System.out.print('\f');
103 99
         } else if(answer.equals("reset")){
104 100
             simpleOp.currentNumber = 0;
105
-            System.out.println(simpleOp.currentNumber);
101
+            //getNumber(Console.getStringInput("Enter Number."));
106 102
         }
107 103
     }
108 104
    
109
-}
105
+}

+ 9
- 1
MainApplication.java Bestand weergeven

@@ -4,8 +4,16 @@
4 4
  */
5 5
 public class MainApplication {
6 6
     public static void main(String[] args) {
7
+        //SWITCH DISPLAY MODE 
8
+        //display.SwitchDisplayMode();
9
+        System.out.println("Current Number: " + simpleOp.currentNumber);
10
+        //simpleOp.currentNumber = Console.getNumber(Console.getStringInput("Enter First Number."));
7 11
         while(true){
8
-            Console.getOp();
12
+            // if(simpleOp.currentNumber == 0){
13
+                // simpleOp.currentNumber = Console.getNumber(Console.getStringInput("Enter First Number."));
14
+            // }else{
15
+                Console.getOp();
16
+            //}
9 17
         }
10 18
     }
11 19
 }

+ 41
- 0
Trigonometry.java Bestand weergeven

@@ -0,0 +1,41 @@
1
+
2
+/**
3
+ * Write a description of class Trigonometry here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Trigonometry
9
+{
10
+    /**
11
+     * Constructor for objects of class Trigonometry
12
+     */
13
+    public Trigonometry()
14
+    {
15
+    }
16
+    //sin
17
+    public static double sin(double x){
18
+        double sin = Math.sin(x);
19
+        return sin;
20
+    }
21
+    //cos
22
+    public static double cos(double x){
23
+        return null;
24
+    }
25
+    //tan
26
+    public static double tan(double x){
27
+        return null;
28
+    }
29
+    //inverse of sin
30
+    public static double sinInverse(double x){
31
+        return null;
32
+    }
33
+    //inverse of cos
34
+    public static double cosInverse(double x){
35
+        return null;
36
+    }
37
+    //inver of tan
38
+    public static double tanInverse(double x){
39
+        return null;
40
+    }
41
+}

+ 31
- 11
opSwitch.java Bestand weergeven

@@ -27,7 +27,17 @@ public class opSwitch
27 27
                 +"invert"+"\n"
28 28
                 +"quit"+"\n"
29 29
                 +"clear"+"\n"
30
-                +"reset"+"\n");
30
+                +"reset"+"\n"
31
+                +"x rooted WIP"+"\n"
32
+                +"log WIP"+"\n"
33
+                +"ln WIP"+"\n"
34
+                +"log (CHANGE OF BASE ) WIP"+"\n"
35
+                +"sin WIP"+"\n"
36
+                +"cos WIP"+"\n"
37
+                +"tan WIP"+"\n"
38
+                +"inverse of sin WIP"+"\n"
39
+                +"inver of cos WIP"+"\n"
40
+                +"inverse of tan WIP"+"\n");
31 41
                 break;
32 42
             case "+": 
33 43
                 //x = Console.getStringInput("Please enter first number.");
@@ -72,17 +82,27 @@ public class opSwitch
72 82
             // default:
73 83
                 // System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands.");
74 84
                 // break;
85
+            case "x rooted":
86
+                break;
87
+            case "log":
88
+                break;
89
+            case "ln":
90
+                break;
91
+            case "log (change of base)":
92
+                break;
93
+            case "sin":
94
+                break;
95
+            case "cos":
96
+                break;
97
+            case "tan":
98
+                break;
99
+            case "inverse of sin":
100
+                break;
101
+            case "inverse of cos":
102
+                break;
103
+            case "inverse of tan":
104
+                break;
75 105
         }
76
-        
77
-        // //if/else state
78
-        // if(opInput.equals("add") || opInput.equals("+")){
79
-            // String addRequest1 = Console.getStringInput("Whats the first number you'll like to add?");
80
-            // String addRequest2 = Console.getStringInput("Whats the second number you'll like to add?");
81
-            // simpleOp.add(Console.getInput(addRequest1), Console.getNumber(addRequest2));
82
-        // }else if(opInput.equals("invert")){
83
-            // String invertRequest = Console.getStringInput("What number would you like to invert?");
84
-            // simpleOp.invert(Console.getInput(invertRequest));
85
-        // 
86 106
     }
87 107
     
88 108
     

+ 36
- 30
package.bluej Bestand weergeven

@@ -2,33 +2,39 @@
2 2
 dependency1.from=ConsoleTest
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=MainApplication
6
-dependency2.to=Console
5
+dependency2.from=opSwitch
6
+dependency2.to=simpleOp
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=Console
9
-dependency3.to=opSwitch
8
+dependency3.from=opSwitch
9
+dependency3.to=Console
10 10
 dependency3.type=UsesDependency
11
-dependency4.from=opSwitch
12
-dependency4.to=Console
11
+dependency4.from=Console
12
+dependency4.to=simpleOp
13 13
 dependency4.type=UsesDependency
14
-dependency5.from=opSwitch
15
-dependency5.to=simpleOp
14
+dependency5.from=Console
15
+dependency5.to=opSwitch
16 16
 dependency5.type=UsesDependency
17
+dependency6.from=MainApplication
18
+dependency6.to=simpleOp
19
+dependency6.type=UsesDependency
20
+dependency7.from=MainApplication
21
+dependency7.to=Console
22
+dependency7.type=UsesDependency
17 23
 editor.fx.0.height=711
18
-editor.fx.0.width=811
19
-editor.fx.0.x=585
20
-editor.fx.0.y=114
24
+editor.fx.0.width=802
25
+editor.fx.0.x=475
26
+editor.fx.0.y=24
21 27
 objectbench.height=199
22 28
 objectbench.width=444
23 29
 package.divider.horizontal=0.6
24 30
 package.divider.vertical=0.6845329249617151
25
-package.editor.height=440
31
+package.editor.height=424
26 32
 package.editor.width=342
27
-package.editor.x=35
28
-package.editor.y=81
33
+package.editor.x=6
34
+package.editor.y=24
29 35
 package.frame.height=711
30 36
 package.frame.width=468
31
-package.numDependencies=5
37
+package.numDependencies=7
32 38
 package.numTargets=5
33 39
 package.showExtends=true
34 40
 package.showUses=true
@@ -43,34 +49,34 @@ target1.name=simpleOp
43 49
 target1.showInterface=false
44 50
 target1.type=ClassTarget
45 51
 target1.width=80
46
-target1.x=130
47
-target1.y=220
52
+target1.x=170
53
+target1.y=210
54
+target2.association=ConsoleTest
48 55
 target2.height=50
49
-target2.name=opSwitch
56
+target2.name=Console
50 57
 target2.showInterface=false
51 58
 target2.type=ClassTarget
52 59
 target2.width=80
53
-target2.x=40
54
-target2.y=160
55
-target3.association=ConsoleTest
60
+target2.x=100
61
+target2.y=110
56 62
 target3.height=50
57
-target3.name=Console
63
+target3.name=opSwitch
58 64
 target3.showInterface=false
59 65
 target3.type=ClassTarget
60 66
 target3.width=80
61
-target3.x=130
62
-target3.y=100
67
+target3.x=30
68
+target3.y=170
63 69
 target4.height=50
64 70
 target4.name=ConsoleTest
65 71
 target4.showInterface=false
66 72
 target4.type=UnitTestTargetJunit4
67 73
 target4.width=80
68
-target4.x=160
69
-target4.y=70
70
-target5.height=40
74
+target4.x=130
75
+target4.y=80
76
+target5.height=50
71 77
 target5.name=MainApplication
72 78
 target5.showInterface=false
73 79
 target5.type=ClassTarget
74
-target5.width=60
75
-target5.x=80
76
-target5.y=30
80
+target5.width=120
81
+target5.x=210
82
+target5.y=10

+ 9
- 3
simpleOp.java Bestand weergeven

@@ -10,6 +10,12 @@ public class simpleOp
10 10
 {
11 11
     public static double currentNumber = 0;
12 12
     
13
+    // public static double NumberOne(){
14
+        // String getFirst = Console.getStringInput("Please enter number.");
15
+        // currentNumber = Console.getNumber(getFirst);
16
+        // return currentNumber;
17
+    // }
18
+    
13 19
     public static double add(double x, double y){
14 20
         //CALULATES THE SUM OF TWO NUMBERS
15 21
         currentNumber = x + y;
@@ -41,7 +47,7 @@ public class simpleOp
41 47
     public static double squ(double x){
42 48
         //CALULATES THE SQUARE OF ONE NUMBER
43 49
         //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
44
-        currentNumber = (int) Math.pow(x,2);
50
+        currentNumber = Math.pow(x,2);
45 51
         //System.out.println(currentNumber);
46 52
         return currentNumber;
47 53
     }
@@ -49,7 +55,7 @@ public class simpleOp
49 55
     public static double sqrt(double x){
50 56
         //CALULATES THE SQUARE ROOT OF ONE NUMBER
51 57
         //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
52
-        currentNumber = (int) Math.sqrt(x);
58
+        currentNumber = Math.sqrt(x);
53 59
         //System.out.println(currentNumber);
54 60
         return currentNumber;
55 61
     }
@@ -57,7 +63,7 @@ public class simpleOp
57 63
     public static double exp(double x, double y){
58 64
         //CALULATES EXPONENTIATION OF X TO POWER OF Y
59 65
         //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
60
-        currentNumber = (int) Math.pow(x,y);
66
+        currentNumber = Math.pow(x,y);
61 67
         //System.out.println(currentNumber);
62 68
         return currentNumber;
63 69
     }