|
@@ -0,0 +1,132 @@
|
|
1
|
+
|
|
2
|
+import java.util.*;
|
|
3
|
+class Calculator{
|
|
4
|
+ public static void main(String args[]){
|
|
5
|
+
|
|
6
|
+ String toDo; //what the user wants to do
|
|
7
|
+ double num1 = 0; //The user's first input
|
|
8
|
+ double num2 = 0; //The user's second input
|
|
9
|
+ double result = 0; //The user's answer
|
|
10
|
+ boolean off = false; //The user typed quit, becomes true
|
|
11
|
+ double memory;
|
|
12
|
+ boolean error = false;
|
|
13
|
+ MathMethods calc = new MathMethods();
|
|
14
|
+
|
|
15
|
+ while (off == false){
|
|
16
|
+ Scanner input1 = new Scanner(System.in);
|
|
17
|
+ System.out.println("What do you want to do?");
|
|
18
|
+ toDo = input1.nextLine();
|
|
19
|
+
|
|
20
|
+ if (toDo.equals("quit")){
|
|
21
|
+ off = true;
|
|
22
|
+ System.out.println("Goodbye!!");
|
|
23
|
+
|
|
24
|
+ } else {
|
|
25
|
+
|
|
26
|
+ //System.out.println("toDO is: " + toDo);
|
|
27
|
+
|
|
28
|
+ System.out.println(toDo + " -- Enter first number:");
|
|
29
|
+ num1 = input1.nextDouble();
|
|
30
|
+ //System.out.println("num1 is: " + num1);
|
|
31
|
+
|
|
32
|
+ switch (toDo){
|
|
33
|
+ case "add":
|
|
34
|
+ case "subtract":
|
|
35
|
+ case "multiply":
|
|
36
|
+ case "divide":
|
|
37
|
+ case "exponent":
|
|
38
|
+ System.out.println(toDo + " -- Enter second number:");
|
|
39
|
+ num2 = input1.nextDouble();
|
|
40
|
+ //System.out.println("num2 is: " + num2);
|
|
41
|
+
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ switch (toDo) {
|
|
45
|
+ case "add":
|
|
46
|
+ result = calc.add(num1, num2);
|
|
47
|
+ memory = result;
|
|
48
|
+ calc.printAns(String.valueOf(result));
|
|
49
|
+ break;
|
|
50
|
+
|
|
51
|
+ case "subtract":
|
|
52
|
+ result = calc.subtract(num1, num2);
|
|
53
|
+ memory = result;
|
|
54
|
+ calc.printAns(String.valueOf(result));
|
|
55
|
+ break;
|
|
56
|
+
|
|
57
|
+ case "multiply":
|
|
58
|
+ result = calc.multiply(num1, num2);
|
|
59
|
+ memory = result;
|
|
60
|
+ calc.printAns(String.valueOf(result));
|
|
61
|
+ break;
|
|
62
|
+
|
|
63
|
+ case "divide":
|
|
64
|
+ result = calc.divide(num1, num2);
|
|
65
|
+ memory = result;
|
|
66
|
+ calc.printAns(String.valueOf(result));
|
|
67
|
+ break;
|
|
68
|
+
|
|
69
|
+ case "exponent":
|
|
70
|
+ result = calc.exponent(num1, num2);
|
|
71
|
+ memory = result;
|
|
72
|
+ calc.printAns(String.valueOf(result));
|
|
73
|
+ break;
|
|
74
|
+
|
|
75
|
+ case "cosine":
|
|
76
|
+ result = calc.cosine(num1);
|
|
77
|
+ memory = result;
|
|
78
|
+ calc.printAns(String.valueOf(result));
|
|
79
|
+ break;
|
|
80
|
+
|
|
81
|
+ case "inverse cosine":
|
|
82
|
+ result = calc.invCosine(num1);
|
|
83
|
+ memory = result;
|
|
84
|
+ calc.printAns(String.valueOf(result));
|
|
85
|
+ break;
|
|
86
|
+
|
|
87
|
+ case "square root":
|
|
88
|
+ result = calc.squareRoot(num1);
|
|
89
|
+ memory = result;
|
|
90
|
+ calc.printAns(String.valueOf(result));
|
|
91
|
+ break;
|
|
92
|
+
|
|
93
|
+ case "invert":
|
|
94
|
+ result = calc.invert(num1);
|
|
95
|
+ memory = result;
|
|
96
|
+ calc.printAns(String.valueOf(result));
|
|
97
|
+ break;
|
|
98
|
+
|
|
99
|
+ case "sine":
|
|
100
|
+ result = calc.sin(num1);
|
|
101
|
+ memory = result;
|
|
102
|
+ calc.printAns(String.valueOf(result));
|
|
103
|
+ break;
|
|
104
|
+
|
|
105
|
+ case "inverse sine":
|
|
106
|
+ result = calc.iSin(num1);
|
|
107
|
+ memory = result;
|
|
108
|
+ calc.printAns(String.valueOf(result));
|
|
109
|
+ break;
|
|
110
|
+
|
|
111
|
+ case "degree to radian":
|
|
112
|
+ result = calc.degToRad(num1);
|
|
113
|
+ memory = result;
|
|
114
|
+ calc.printAns(String.valueOf(result));
|
|
115
|
+ break;
|
|
116
|
+
|
|
117
|
+ case "radian to degree":
|
|
118
|
+ result = calc.radToDeg(num1);
|
|
119
|
+ memory = result;
|
|
120
|
+ calc.printAns(String.valueOf(result));
|
|
121
|
+ break;
|
|
122
|
+
|
|
123
|
+ case "roundTo":
|
|
124
|
+ memory = result;
|
|
125
|
+ calc.roundTo(memory, (int)num1);
|
|
126
|
+ break;
|
|
127
|
+ }
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ }
|
|
131
|
+ }
|
|
132
|
+}
|