|
@@ -1,81 +1,119 @@
|
1
|
1
|
|
2
|
2
|
public class MainApplication {
|
3
|
|
- int display = 0;
|
4
|
|
- int memory = 0;
|
|
3
|
+ double display = 0;
|
|
4
|
+ //Changed all int to double. If a decimal was entered first, it would
|
|
5
|
+ //create an error.
|
5
|
6
|
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
6
|
10
|
public static void main(String[] args) {
|
7
|
11
|
Console.println("Welcome to Vince and Ray's Calculator!");
|
8
|
|
- Integer display = Console.getIntegerInput("Enter your first integer: ");
|
9
|
12
|
while(true){
|
10
|
|
- String operator = Console.getStringInput("Enter the operation you'd like to perform or type\n'help' to see a list of commands.");
|
11
|
|
- if(operator.equalsIgnoreCase("Add")){
|
12
|
|
- Integer entered = Console.getIntegerInput("Enter your second integer: ");
|
13
|
|
- CoreFunctions.add(display, entered);
|
14
|
|
- display = display + entered;
|
15
|
|
- }
|
16
|
|
- if(operator.equalsIgnoreCase("Subtract")){
|
17
|
|
- Integer entered = Console.getIntegerInput("Enter your second integer: ");
|
18
|
|
- CoreFunctions.subtract(display, entered);
|
19
|
|
- display = display - entered;
|
20
|
|
- }
|
21
|
|
- if(operator.equalsIgnoreCase("Multiply")){
|
22
|
|
- Integer entered = Console.getIntegerInput("Enter your second integer: ");
|
23
|
|
- CoreFunctions.multiply(display, entered);
|
24
|
|
- display = display * entered;
|
25
|
|
- }
|
26
|
|
- if(operator.equalsIgnoreCase("Divide")){
|
27
|
|
- Integer entered = Console.getIntegerInput("Enter your second integer: ");
|
28
|
|
- if(entered != 0){
|
29
|
|
- CoreFunctions.divide(display, entered);
|
30
|
|
- display = display / entered;
|
31
|
|
- }else {
|
32
|
|
- System.out.println("Err");
|
|
13
|
+ //Created a try catch methtod to catch all errors of the loop.
|
|
14
|
+ //and tell you where the error origin.
|
|
15
|
+ try{
|
|
16
|
+ Double display = Console.getDoubleInput("Enter your first number: ");
|
|
17
|
+ String operator = Console.getStringInput("Enter the operation you'd like to perform or type\n'help' to see a list of commands.");
|
|
18
|
+ if(operator.equalsIgnoreCase("Add")){
|
|
19
|
+ Integer entered = Console.getIntegerInput("Enter your second integer: ");
|
|
20
|
+ CoreFunctions.add(display, entered);
|
|
21
|
+ display = display + entered;
|
33
|
22
|
}
|
|
23
|
+ if(operator.equalsIgnoreCase("Subtract")){
|
|
24
|
+
|
|
25
|
+ Integer entered = Console.getIntegerInput("Enter your second integer: ");
|
|
26
|
+ CoreFunctions.subtract(display, entered);
|
|
27
|
+ display = display - entered;
|
|
28
|
+ }
|
|
29
|
+ if(operator.equalsIgnoreCase("Multiply")){
|
|
30
|
+ Integer entered = Console.getIntegerInput("Enter your second integer: ");
|
|
31
|
+ CoreFunctions.multiply(display, entered);
|
|
32
|
+ display = display * entered;
|
|
33
|
+ }
|
|
34
|
+ if(operator.equalsIgnoreCase("Divide")){
|
|
35
|
+ Double entered = Console.getDoubleInput("Enter your second integer: ");
|
|
36
|
+ if(entered != 0){
|
|
37
|
+ CoreFunctions.divide(display, entered);
|
|
38
|
+ display = display / entered;
|
|
39
|
+ }else {
|
|
40
|
+ System.out.println("Err");
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+ if(operator.equalsIgnoreCase("Exponent")){
|
|
44
|
+ Double entered = Console.getDoubleInput("Enter your second integer: ");
|
|
45
|
+ CoreFunctions.exp(display, entered);
|
|
46
|
+ display = (double) Math.pow(display,entered);
|
|
47
|
+ }
|
|
48
|
+ if(operator.equalsIgnoreCase("squared")){
|
|
49
|
+ ScientificFunctions.sqr(display);
|
|
50
|
+ display = display*display;
|
|
51
|
+ }
|
|
52
|
+ if(operator.equalsIgnoreCase("square root")){
|
|
53
|
+ ScientificFunctions.sqRoot(display);
|
|
54
|
+ display = ((double)Math.sqrt(display));
|
|
55
|
+ }
|
|
56
|
+ if(operator.equalsIgnoreCase("Inverse Fraction")){
|
|
57
|
+ ScientificFunctions.invFraction(display);
|
|
58
|
+ display = 1/display;
|
|
59
|
+ }
|
|
60
|
+ if(operator.equalsIgnoreCase("Inverse Sign")){
|
|
61
|
+ ScientificFunctions.invSign(display);
|
|
62
|
+ display = -1/display;
|
|
63
|
+ }
|
|
64
|
+ if(operator.equalsIgnoreCase("sine")){
|
|
65
|
+ ScientificFunctions.sine(display);
|
|
66
|
+ display = (double)Math.sin(display);
|
|
67
|
+ }
|
|
68
|
+ if(operator.equalsIgnoreCase("cosine")){
|
|
69
|
+ ScientificFunctions.cosine(display);
|
|
70
|
+ display = (double)Math.cos(display);
|
|
71
|
+ }
|
|
72
|
+ if(operator.equalsIgnoreCase("tangent")){
|
|
73
|
+ ScientificFunctions.tan(display);
|
|
74
|
+ display = (double)Math.tan(display);
|
|
75
|
+ }
|
|
76
|
+ if(operator.equalsIgnoreCase("inverse tangent")){
|
|
77
|
+ ScientificFunctions.atan(display);
|
|
78
|
+ display = (double)Math.atan(display);
|
|
79
|
+ }
|
|
80
|
+ if(operator.equalsIgnoreCase("inverse sin")){
|
|
81
|
+ ScientificFunctions.asin(display);
|
|
82
|
+ display = (double)Math.asin(display);
|
|
83
|
+ }
|
|
84
|
+ if(operator.equalsIgnoreCase("inverse cosine")){
|
|
85
|
+ ScientificFunctions.acosin(display);
|
|
86
|
+ display = (double)Math.acos(display);
|
|
87
|
+ }
|
|
88
|
+ if(operator.equalsIgnoreCase("M+")){
|
|
89
|
+ ScientificFunctions.setMem(display);
|
|
90
|
+ }
|
|
91
|
+ if(operator.equalsIgnoreCase("MC")){
|
|
92
|
+ ScientificFunctions.resetMem(display);
|
|
93
|
+ }
|
|
94
|
+ if(operator.equalsIgnoreCase("MRC")){
|
|
95
|
+ ScientificFunctions.recallMem(display);
|
|
96
|
+ }
|
|
97
|
+ if(operator.equalsIgnoreCase("clear")){
|
|
98
|
+ System.out.print('\u000C');
|
|
99
|
+ }
|
|
100
|
+ if(operator.equalsIgnoreCase("exit")){
|
|
101
|
+ System.out.println("Thanks for using our Calculator!");
|
|
102
|
+ break;
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ }catch(Exception e){
|
|
106
|
+ System.err.println(e);
|
|
107
|
+ System.err.println("System Error: Try again");
|
|
108
|
+ continue;
|
|
109
|
+
|
34
|
110
|
}
|
35
|
|
- if(operator.equalsIgnoreCase("Exponent")){
|
36
|
|
- Integer entered = Console.getIntegerInput("Enter your second integer: ");
|
37
|
|
- CoreFunctions.exp(display, entered);
|
38
|
|
- display = (int)Math.pow(display,entered);
|
39
|
|
- }
|
40
|
|
- if(operator.equalsIgnoreCase("squared")){
|
41
|
|
- ScientificFunctions.sqr(display);
|
42
|
|
- display = display*display;
|
43
|
|
- }
|
44
|
|
- if(operator.equalsIgnoreCase("square root")){
|
45
|
|
- ScientificFunctions.sqRoot(display);
|
46
|
|
- display = ((int)Math.sqrt(display));
|
47
|
|
- }
|
48
|
|
- if(operator.equalsIgnoreCase("Inverse Fraction")){
|
49
|
|
- ScientificFunctions.invFraction(display);
|
50
|
|
- display = 1/display;
|
51
|
|
- }
|
52
|
|
- if(operator.equalsIgnoreCase("Inverse Sign")){
|
53
|
|
- ScientificFunctions.invSign(display);
|
54
|
|
- display = -1/display;
|
55
|
|
- }
|
56
|
|
- if(operator.equalsIgnoreCase("sine")){
|
57
|
|
- ScientificFunctions.sine(display);
|
58
|
|
- display = (int)Math.sin(display);
|
59
|
|
- }
|
60
|
|
- if(operator.equalsIgnoreCase("cosine")){
|
61
|
|
- ScientificFunctions.cosine(display);
|
62
|
|
- display = (int)Math.cos(display);
|
63
|
|
- }
|
64
|
|
- if(operator.equalsIgnoreCase("tangent")){
|
65
|
|
- ScientificFunctions.tan(display);
|
66
|
|
- display = (int)Math.tan(display);
|
67
|
|
- }
|
68
|
|
- if(operator.equalsIgnoreCase("exit")){
|
69
|
|
- System.out.println("Thanks for using our Calculator!");
|
70
|
|
- break;
|
71
|
|
- }
|
72
|
|
- }
|
73
|
111
|
|
|
112
|
+ }
|
74
|
113
|
}
|
75
|
114
|
|
76
|
115
|
}
|
77
|
116
|
|
78
|
|
-
|
79
|
117
|
//Integer i = Console.getIntegerInput("Enter an integer");
|
80
|
118
|
//Double d = Console.getDoubleInput("Enter a double.");
|
81
|
119
|
|