|
@@ -7,72 +7,114 @@ public class Main{
|
7
|
7
|
|
8
|
8
|
//Calls class Calculator, Console, and Memory
|
9
|
9
|
Calculator calc = new Calculator();
|
10
|
|
- Memory memory = new Memory();
|
|
10
|
+ Memory memo = new Memory();
|
11
|
11
|
|
12
|
12
|
//User input
|
13
|
13
|
Scanner reader = new Scanner(System.in);
|
14
|
|
- System.out.println("Welcome to Calculator!");
|
|
14
|
+ Console.println("Welcome to Calculator!");
|
15
|
15
|
double value = 0;
|
|
16
|
+ double saveValue = 0;
|
16
|
17
|
|
17
|
|
- while(true){
|
18
|
|
- System.out.println("0");
|
19
|
|
- Console.println("(-) to Invert");
|
20
|
|
- double x = reader.nextDouble();
|
21
|
|
- String toggleInvert = reader.next();
|
22
|
|
- reader.nextLine();
|
23
|
|
-
|
24
|
|
-
|
25
|
|
- switch(toggleInvert){
|
|
18
|
+
|
|
19
|
+ while(true){
|
|
20
|
+ Console.println("Pick Operation: Clear (-) + - * / Sq SqRt Power\nPick Operation: Cos Sin Tan -Cos -Sin -Tan");
|
|
21
|
+ String button = reader.nextLine();
|
|
22
|
+ double x = saveValue;
|
|
23
|
+ ArrayList<String> button1 = Arrays.asList("(-)", "Sq", "SqRt", "Cos", "Sin", "Tan", "-Cos", "-Sin", "-Tan");
|
|
24
|
+ ArrayList<String> button2 = Arrays.asList("+","-","*","/","Power");
|
|
25
|
+
|
|
26
|
+ if(saveValue == 0){
|
|
27
|
+ x = Console.getDoubleInput("Input number:");
|
|
28
|
+ }else if(button.equalsIgnoreCase("Clear")){
|
|
29
|
+ continue;
|
|
30
|
+ }else if(button1.contains(
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+ switch(button1){
|
26
|
34
|
case "(-)":
|
27
|
35
|
value = calc.invert(x);
|
28
|
|
- System.out.print(value);
|
29
|
|
- while(true){
|
30
|
|
-
|
31
|
|
- Console.println("Choose an operation:OFF + - * /");
|
32
|
|
- String button = reader.nextLine();
|
33
|
|
- reader.nextLine();
|
34
|
|
- System.out.println("");
|
35
|
|
- double y = reader.nextDouble();
|
36
|
|
-
|
|
36
|
+ saveValue = value;
|
|
37
|
+ Console.println(Double.toString(value));
|
|
38
|
+ break;
|
|
39
|
+ case "Sq":
|
|
40
|
+ value = calc.square(x);
|
|
41
|
+ saveValue = value;
|
|
42
|
+ Console.println(Double.toString(value));
|
|
43
|
+ break;
|
|
44
|
+ case "SqRt":
|
|
45
|
+ value = calc.squareRoot(x);
|
|
46
|
+ saveValue = value;
|
|
47
|
+ Console.println(Double.toString(value));
|
|
48
|
+ break;
|
|
49
|
+ case "Cos":
|
|
50
|
+ value = calc.getCosine(x);
|
|
51
|
+ saveValue = value;
|
|
52
|
+ Console.println(Double.toString(value));
|
|
53
|
+ break;
|
|
54
|
+ case "Sin":
|
|
55
|
+ value = calc.getSine(x);
|
|
56
|
+ saveValue = value;
|
|
57
|
+ Console.println(Double.toString(value));
|
|
58
|
+ break;
|
|
59
|
+ case "Tan":
|
|
60
|
+ value = calc.getTan(x);
|
|
61
|
+ saveValue = value;
|
|
62
|
+ Console.println(Double.toString(value));
|
|
63
|
+ break;
|
|
64
|
+ case "-Cos":
|
|
65
|
+ value = calc.inverseCos(x);
|
|
66
|
+ saveValue = value;
|
|
67
|
+ Console.println(Double.toString(value));
|
|
68
|
+ break;
|
|
69
|
+ case "-Sin":
|
|
70
|
+ value = calc.inverseSin(x);
|
|
71
|
+ saveValue = value;
|
|
72
|
+ Console.println(Double.toString(value));
|
|
73
|
+ break;
|
|
74
|
+ case "-Tan":
|
|
75
|
+ value = calc.inverseTan(x);
|
|
76
|
+ saveValue = value;
|
|
77
|
+ Console.println(Double.toString(value));
|
|
78
|
+ break;
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ double y = Console.getDoubleInput("Input Number:");
|
|
82
|
+
|
|
83
|
+ switch(button2){
|
|
84
|
+ case "Clear":
|
|
85
|
+ value = 0;
|
|
86
|
+ break;
|
|
87
|
+ case "+":
|
|
88
|
+ value = calc.add(x, y);
|
|
89
|
+ saveValue = value;
|
|
90
|
+ Console.println(Double.toString(value));
|
|
91
|
+ break;
|
|
92
|
+ case "-":
|
|
93
|
+ value = calc.subtract(x, y);
|
|
94
|
+ saveValue = value;
|
|
95
|
+ Console.println(Double.toString(value));
|
|
96
|
+ break;
|
|
97
|
+ case "*":
|
|
98
|
+ value = calc.multiply(x, y);
|
|
99
|
+ saveValue = value;
|
|
100
|
+ Console.println(Double.toString(value));
|
|
101
|
+ break;
|
|
102
|
+ case "/":
|
|
103
|
+ value = calc.divide(x, y);
|
|
104
|
+ saveValue = value;
|
|
105
|
+ Console.println(Double.toString(value));
|
|
106
|
+ break;
|
|
107
|
+ case "Power":
|
|
108
|
+ value = calc.getPow(x, y);
|
|
109
|
+ saveValue = value;
|
|
110
|
+ Console.println(Double.toString(value));
|
|
111
|
+ break;
|
|
112
|
+ default:
|
|
113
|
+ Console.print("Err");
|
|
114
|
+ break;
|
|
115
|
+ }
|
37
|
116
|
|
38
|
|
- switch(button){
|
39
|
|
- case "OFF":
|
40
|
|
- return;
|
41
|
|
- case "+":
|
42
|
|
- value = calc.add(x, y);
|
43
|
|
- System.out.print(value);
|
44
|
|
- break;
|
45
|
|
- case "-":
|
46
|
|
- value = calc.subtract(x, y);
|
47
|
|
- System.out.print(value);
|
48
|
|
- break;
|
49
|
|
- case "*":
|
50
|
|
- value = calc.multiply(x, y);
|
51
|
|
- System.out.print(value);
|
52
|
|
- break;
|
53
|
|
- case "/":
|
54
|
|
- value = calc.divide(x, y);
|
55
|
|
- System.out.print(value);
|
56
|
|
- break;
|
57
|
|
- case "Sq":
|
58
|
|
- value = calc.square(x);
|
59
|
|
- System.out.print(value);
|
60
|
|
- break;
|
61
|
|
- case "SqRoot":
|
62
|
|
- value = calc.squareRoot(x);
|
63
|
|
- System.out.print(value);
|
64
|
|
- break;
|
65
|
|
- case "Power":
|
66
|
|
- value = calc.getPow(x, y);
|
67
|
|
- System.out.print(value);
|
68
|
|
- break;
|
69
|
|
- default:
|
70
|
|
- System.out.println("Error");
|
71
|
|
- }
|
72
|
|
- }
|
73
|
|
-
|
74
|
|
- }
|
75
|
|
-
|
76
|
117
|
}
|
77
|
118
|
}
|
78
|
|
-}
|
|
119
|
+}
|
|
120
|
+
|