|
@@ -13,50 +13,17 @@ public class Basic
|
13
|
13
|
String operation = "";
|
14
|
14
|
double answer;
|
15
|
15
|
|
16
|
|
- public double Basic()
|
|
16
|
+ public void Basic()
|
17
|
17
|
{
|
18
|
|
-
|
19
|
|
- //Get input of first number
|
20
|
|
- input1 = Console.getDoubleInput("What is the first number?");
|
21
|
|
-
|
22
|
|
- //Get input of operation
|
23
|
|
- operation = Console.getStringInput("Which operation would you like to perform? \n +, -, *, /");
|
24
|
|
-
|
25
|
|
- //Get input of second number
|
26
|
|
- input2 = Console.getDoubleInput("What is the second number?");
|
27
|
|
-
|
28
|
|
- //Do the math depending on the inputs.
|
29
|
|
- //addition
|
30
|
|
- if (operation.equals("+")) {
|
31
|
|
- getSum(input1, input2);
|
32
|
|
-
|
33
|
|
- //subtraction
|
34
|
|
- } else if (operation.equals("-")) {
|
35
|
|
- getDiff(input1, input2);
|
36
|
|
-
|
37
|
|
- //multiplication
|
38
|
|
- } else if (operation.equals("*")) {
|
39
|
|
- getProduct(input1, input2);
|
40
|
|
-
|
41
|
|
- //division
|
42
|
|
- } else if (operation.equals("/")) {
|
43
|
|
- //error message when trying to divide by 0.
|
44
|
|
- if (input2 == 0) {
|
45
|
|
- Console.println("undefined");
|
46
|
|
- //Insert return to main menu.
|
47
|
|
- } else {
|
48
|
|
- getQuotient(input1, input2);
|
49
|
|
- }
|
50
|
|
- } else {
|
51
|
|
- //error if wrong input was entered
|
52
|
|
- answer = Double.NaN;
|
53
|
|
-
|
54
|
|
-
|
|
18
|
+ Console.println("Basic Calculator Options"
|
|
19
|
+ + "\n+: Addition"
|
|
20
|
+ + "\n-: Subtraction"
|
|
21
|
+ + "\n*: Multiplication"
|
|
22
|
+ + "\n/: Division"
|
|
23
|
+ + "\n5: Cancel - returns to Main Menu");
|
|
24
|
+
|
55
|
25
|
}
|
56
|
|
-
|
57
|
|
- return answer;
|
58
|
26
|
|
59
|
|
-}
|
60
|
27
|
//addition method
|
61
|
28
|
public double getSum(double x, double y) {
|
62
|
29
|
answer = x + y;
|