Browse Source

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

William Brown 6 years ago
parent
commit
7148ab596b
6 changed files with 157 additions and 80 deletions
  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 View File

4
  * Created by leon on 2/9/18.
4
  * Created by leon on 2/9/18.
5
  */
5
  */
6
 public class Console {
6
 public class Console {
7
-
7
+    //GIVEN TO US 
8
     public static void print(String output, Object... args) {
8
     public static void print(String output, Object... args) {
9
         System.out.printf(output, args);
9
         System.out.printf(output, args);
10
     }
10
     }
11
-
11
+    //GIVEN TO US
12
     public static void println(String output, Object... args) {
12
     public static void println(String output, Object... args) {
13
         print(output + "\n", args);
13
         print(output + "\n", args);
14
     }
14
     }
15
-    
15
+    //GIVEN TO US
16
     public static String getStringInput(String prompt) {
16
     public static String getStringInput(String prompt) {
17
         Scanner scanner = new Scanner(System.in);
17
         Scanner scanner = new Scanner(System.in);
18
         println(prompt);
18
         println(prompt);
19
         String userInput = scanner.nextLine();
19
         String userInput = scanner.nextLine();
20
         return userInput;
20
         return userInput;
21
     }
21
     }
22
-
22
+    //GIVEN TO US
23
     public static Integer  getIntInput(String prompt) {
23
     public static Integer  getIntInput(String prompt) {
24
         Scanner scanner = new Scanner(System.in);
24
         Scanner scanner = new Scanner(System.in);
25
         println(prompt);
25
         println(prompt);
26
         int userInput = scanner.nextInt();
26
         int userInput = scanner.nextInt();
27
         return userInput;
27
         return userInput;
28
     }
28
     }
29
-
29
+    //GIVEN TO US
30
     public static Double getDoubleInput(String prompt) {
30
     public static Double getDoubleInput(String prompt) {
31
         Scanner scanner = new Scanner(System.in);
31
         Scanner scanner = new Scanner(System.in);
32
         println(prompt);
32
         println(prompt);
40
             //return display;
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
     public static double invert(double number){
56
     public static double invert(double number){
61
         //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
57
         //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
69
     }
65
     }
70
     */
66
     */
71
     public static double getNumber(String numberString){
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
     public static String getOp(){
81
     public static String getOp(){
96
     }
92
     }
97
     
93
     
98
     public static void quit(String answer){
94
     public static void quit(String answer){
99
-        if(answer.equals("quit") || answer.equals("exit")){
95
+        if(answer.equals("quit")){
100
             System.exit(0);
96
             System.exit(0);
101
         } else if(answer.equals("clear")) {
97
         } else if(answer.equals("clear")) {
102
             System.out.print('\f');
98
             System.out.print('\f');
103
         } else if(answer.equals("reset")){
99
         } else if(answer.equals("reset")){
104
             simpleOp.currentNumber = 0;
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 View File

4
  */
4
  */
5
 public class MainApplication {
5
 public class MainApplication {
6
     public static void main(String[] args) {
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
         while(true){
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 View File

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 View File

27
                 +"invert"+"\n"
27
                 +"invert"+"\n"
28
                 +"quit"+"\n"
28
                 +"quit"+"\n"
29
                 +"clear"+"\n"
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
                 break;
41
                 break;
32
             case "+": 
42
             case "+": 
33
                 //x = Console.getStringInput("Please enter first number.");
43
                 //x = Console.getStringInput("Please enter first number.");
72
             // default:
82
             // default:
73
                 // System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands.");
83
                 // System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands.");
74
                 // break;
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 View File

2
 dependency1.from=ConsoleTest
2
 dependency1.from=ConsoleTest
3
 dependency1.to=Console
3
 dependency1.to=Console
4
 dependency1.type=UsesDependency
4
 dependency1.type=UsesDependency
5
-dependency2.from=MainApplication
6
-dependency2.to=Console
5
+dependency2.from=opSwitch
6
+dependency2.to=simpleOp
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
-dependency3.from=Console
9
-dependency3.to=opSwitch
8
+dependency3.from=opSwitch
9
+dependency3.to=Console
10
 dependency3.type=UsesDependency
10
 dependency3.type=UsesDependency
11
-dependency4.from=opSwitch
12
-dependency4.to=Console
11
+dependency4.from=Console
12
+dependency4.to=simpleOp
13
 dependency4.type=UsesDependency
13
 dependency4.type=UsesDependency
14
-dependency5.from=opSwitch
15
-dependency5.to=simpleOp
14
+dependency5.from=Console
15
+dependency5.to=opSwitch
16
 dependency5.type=UsesDependency
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
 editor.fx.0.height=711
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
 objectbench.height=199
27
 objectbench.height=199
22
 objectbench.width=444
28
 objectbench.width=444
23
 package.divider.horizontal=0.6
29
 package.divider.horizontal=0.6
24
 package.divider.vertical=0.6845329249617151
30
 package.divider.vertical=0.6845329249617151
25
-package.editor.height=440
31
+package.editor.height=424
26
 package.editor.width=342
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
 package.frame.height=711
35
 package.frame.height=711
30
 package.frame.width=468
36
 package.frame.width=468
31
-package.numDependencies=5
37
+package.numDependencies=7
32
 package.numTargets=5
38
 package.numTargets=5
33
 package.showExtends=true
39
 package.showExtends=true
34
 package.showUses=true
40
 package.showUses=true
43
 target1.showInterface=false
49
 target1.showInterface=false
44
 target1.type=ClassTarget
50
 target1.type=ClassTarget
45
 target1.width=80
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
 target2.height=50
55
 target2.height=50
49
-target2.name=opSwitch
56
+target2.name=Console
50
 target2.showInterface=false
57
 target2.showInterface=false
51
 target2.type=ClassTarget
58
 target2.type=ClassTarget
52
 target2.width=80
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
 target3.height=50
62
 target3.height=50
57
-target3.name=Console
63
+target3.name=opSwitch
58
 target3.showInterface=false
64
 target3.showInterface=false
59
 target3.type=ClassTarget
65
 target3.type=ClassTarget
60
 target3.width=80
66
 target3.width=80
61
-target3.x=130
62
-target3.y=100
67
+target3.x=30
68
+target3.y=170
63
 target4.height=50
69
 target4.height=50
64
 target4.name=ConsoleTest
70
 target4.name=ConsoleTest
65
 target4.showInterface=false
71
 target4.showInterface=false
66
 target4.type=UnitTestTargetJunit4
72
 target4.type=UnitTestTargetJunit4
67
 target4.width=80
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
 target5.name=MainApplication
77
 target5.name=MainApplication
72
 target5.showInterface=false
78
 target5.showInterface=false
73
 target5.type=ClassTarget
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 View File

10
 {
10
 {
11
     public static double currentNumber = 0;
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
     public static double add(double x, double y){
19
     public static double add(double x, double y){
14
         //CALULATES THE SUM OF TWO NUMBERS
20
         //CALULATES THE SUM OF TWO NUMBERS
15
         currentNumber = x + y;
21
         currentNumber = x + y;
41
     public static double squ(double x){
47
     public static double squ(double x){
42
         //CALULATES THE SQUARE OF ONE NUMBER
48
         //CALULATES THE SQUARE OF ONE NUMBER
43
         //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
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
         //System.out.println(currentNumber);
51
         //System.out.println(currentNumber);
46
         return currentNumber;
52
         return currentNumber;
47
     }
53
     }
49
     public static double sqrt(double x){
55
     public static double sqrt(double x){
50
         //CALULATES THE SQUARE ROOT OF ONE NUMBER
56
         //CALULATES THE SQUARE ROOT OF ONE NUMBER
51
         //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
57
         //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
52
-        currentNumber = (int) Math.sqrt(x);
58
+        currentNumber = Math.sqrt(x);
53
         //System.out.println(currentNumber);
59
         //System.out.println(currentNumber);
54
         return currentNumber;
60
         return currentNumber;
55
     }
61
     }
57
     public static double exp(double x, double y){
63
     public static double exp(double x, double y){
58
         //CALULATES EXPONENTIATION OF X TO POWER OF Y
64
         //CALULATES EXPONENTIATION OF X TO POWER OF Y
59
         //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
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
         //System.out.println(currentNumber);
67
         //System.out.println(currentNumber);
62
         return currentNumber;
68
         return currentNumber;
63
     }
69
     }