|
@@ -1,12 +1,128 @@
|
1
|
|
-
|
2
|
1
|
|
3
|
2
|
import java.util.Scanner;
|
4
|
|
-
|
5
|
3
|
/**
|
6
|
4
|
* Created by leon on 2/9/18.
|
7
|
5
|
*/
|
8
|
6
|
public class Console {
|
9
|
7
|
|
|
8
|
+ public static void main(String[] args) {
|
|
9
|
+ double answer;
|
|
10
|
+ // Create all instances of classes to be used for this program
|
|
11
|
+ MainMenu mainMenu = new MainMenu();
|
|
12
|
+ Basic basicCalc = new Basic();
|
|
13
|
+ SciCalc scientificCalc = new SciCalc();
|
|
14
|
+ MemoryFunc memory = new MemoryFunc();
|
|
15
|
+ SwitchDisplay baseChange = new SwitchDisplay();
|
|
16
|
+ Trig trigMenu = new Trig();
|
|
17
|
+
|
|
18
|
+ // Stored memory value should be able to be used throughout whole application
|
|
19
|
+ Double memoryValue = memory.memory;
|
|
20
|
+
|
|
21
|
+ // blanket input statement
|
|
22
|
+ // create input methods to call when we need them with specific types
|
|
23
|
+ // we use 1 input variable statement to call the user to input, then manipulate
|
|
24
|
+ // Can user input M if native type is double
|
|
25
|
+ // if any input = "m", that input now = memoryValue;
|
|
26
|
+
|
|
27
|
+ // Menu Input
|
|
28
|
+ String menuInput = " ";
|
|
29
|
+ // Giant while loop that links back to main menu
|
|
30
|
+ while (!menuInput.equals("4")) {
|
|
31
|
+ mainMenu.mainMenuDisplay();
|
|
32
|
+ menuInput = Console.getStringInput("Enter the calculator you want to use by key. (ie. 1 for basic, etc.)");
|
|
33
|
+
|
|
34
|
+ switch (menuInput) {
|
|
35
|
+ case "1":
|
|
36
|
+ basicCalc.Basic();
|
|
37
|
+
|
|
38
|
+ double basicInput1 = Console.getIntegerInput("Enter the first input: ");
|
|
39
|
+
|
|
40
|
+ String basicMode = Console.getStringInput("Enter the mode: ");
|
|
41
|
+
|
|
42
|
+ double basicInput2 = Console.getIntegerInput("Enter the second input: ");
|
|
43
|
+
|
|
44
|
+ if (basicMode.equals("+")) {
|
|
45
|
+ basicCalc.getSum(basicInput1, basicInput2);
|
|
46
|
+
|
|
47
|
+ //subtraction
|
|
48
|
+ } else if (basicMode.equals("-")) {
|
|
49
|
+ basicCalc.getDiff(basicInput1, basicInput2);
|
|
50
|
+
|
|
51
|
+ //multiplication
|
|
52
|
+ } else if (basicMode.equals("*")) {
|
|
53
|
+ basicCalc.getProduct(basicInput1, basicInput2);
|
|
54
|
+
|
|
55
|
+ //division
|
|
56
|
+ } else if (basicMode.equals("/")) {
|
|
57
|
+ //error message when trying to divide by 0.
|
|
58
|
+ if (basicInput2 == 0) {
|
|
59
|
+ Console.println("undefined");
|
|
60
|
+ //Insert return to main menu.
|
|
61
|
+ } else {
|
|
62
|
+ basicCalc.getQuotient(basicInput1, basicInput2);
|
|
63
|
+ }
|
|
64
|
+ } else {
|
|
65
|
+ //error if wrong input was entered
|
|
66
|
+ answer = Double.NaN;
|
|
67
|
+ Console.println("Invalid Input");
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+ break;
|
|
72
|
+
|
|
73
|
+ case "2":
|
|
74
|
+
|
|
75
|
+ // Sends to Advanced Calculator Functions
|
|
76
|
+ break;
|
|
77
|
+
|
|
78
|
+ case "3":
|
|
79
|
+
|
|
80
|
+ // Sends to Scientific Calculator Functions
|
|
81
|
+ // displays the menu for scientific calc
|
|
82
|
+ scientificCalc.toSciMenu();
|
|
83
|
+ String sciMenuInput = Console.getStringInput("Enter the function you'd like to use by key.");
|
|
84
|
+ // if statement to use various calc functions
|
|
85
|
+ if (sciMenuInput.equals("1")) {
|
|
86
|
+ // Base Conversions
|
|
87
|
+ // while loop for display
|
|
88
|
+ String mode = "";
|
|
89
|
+ while (!mode.equals("Invalid Input")) {
|
|
90
|
+ baseChange.switchDisplay();
|
|
91
|
+ mode = Console.getStringInput("Enter the desired display mode: ");
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ int userInput = getIntegerInput("Enter the number you want to convert to selected base: ");
|
|
95
|
+ baseChange.switchDisplayOutput(mode, userInput);
|
|
96
|
+
|
|
97
|
+ // display mode
|
|
98
|
+ // gets mode
|
|
99
|
+ // asks for input
|
|
100
|
+ } else if (sciMenuInput.equals("2")) {
|
|
101
|
+ // Memory
|
|
102
|
+ memory.memoryMenu();
|
|
103
|
+ } else if (sciMenuInput.equals("3")) {
|
|
104
|
+ // To Trig Menu
|
|
105
|
+ answer = trigMenu.TrigFunctions();
|
|
106
|
+ Console.println(Double.toString(answer));
|
|
107
|
+ String response = Console.getStringInput("Would you like to convert your answer from radian to degrees? Y or N").toLowerCase();
|
|
108
|
+
|
|
109
|
+ if (response.equals("y") ) {
|
|
110
|
+ trigMenu.toDegrees(answer);
|
|
111
|
+ }
|
|
112
|
+ break;
|
|
113
|
+ } else {
|
|
114
|
+ break;
|
|
115
|
+ }
|
|
116
|
+ break;
|
|
117
|
+
|
|
118
|
+ case "4":
|
|
119
|
+ // Quits the calculator
|
|
120
|
+ break;
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ }
|
|
124
|
+ }
|
|
125
|
+
|
10
|
126
|
public static void print(String output, Object... args) {
|
11
|
127
|
System.out.printf(output, args);
|
12
|
128
|
}
|