import java.util.Scanner; /** * Created by leon on 2/9/18. */ public class Console { public static void main(String[] args) { // Create all instances of classes to be used for this program MainMenu mainMenu = new MainMenu(); Basic basicCalc = new Basic(); RealAdvanced advCalc = new RealAdvanced(); SciCalc scientificCalc = new SciCalc(); MemoryFunc memory = new MemoryFunc(); SwitchDisplay baseChange = new SwitchDisplay(); Trig trigMenu = new Trig(); // Stored memory value should be able to be used throughout whole application Double memoryValue = memory.memory; // blanket input statement // create input methods to call when we need them with specific types // we use 1 input variable statement to call the user to input, then manipulate // Can user input M if native type is double // if any input = "m", that input now = memoryValue; // Menu Input String menuInput = " "; // Giant while loop that links back to main menu while (!menuInput.equals("4")) { mainMenu.mainMenuDisplay(); menuInput = Console.getStringInput("Enter the calculator you want to use by key. (ie. 1 for basic, etc.)"); switch (menuInput) { // Basic Calculator case "1": basicCalc.Basic(); String basicMode = Console.getStringInput("Enter the mode: "); double basicInput1 = Console.getDoubleInput("Enter the first input: "); double basicInput2 = Console.getDoubleInput("Enter the second input: "); double basicAnswer = 0; if (basicMode.equals("1")) { basicAnswer = basicCalc.getSum(basicInput1, basicInput2); //subtraction } else if (basicMode.equals("2")) { basicAnswer = basicCalc.getDiff(basicInput1, basicInput2); //multiplication } else if (basicMode.equals("3")) { basicAnswer = basicCalc.getProduct(basicInput1, basicInput2); //division } else if (basicMode.equals("4")) { //error message when trying to divide by 0. if (basicInput2 == 0) { Console.println("undefined"); //Insert return to main menu. } else { basicAnswer = basicCalc.getQuotient(basicInput1, basicInput2); } } else if (basicMode.equals("5")) { break; } else { //error if wrong input was entered basicAnswer = Double.NaN; Console.println("Invalid Input"); } Console.println(Double.toString(basicAnswer)); break; case "2": advCalc.realAdvanced(); String mode = Console.getStringInput("Enter the mode: "); double advInput1 = Console.getDoubleInput("Enter the first input: "); double advAnswer = 0; if (mode.equals("1")){ advAnswer = advCalc.squared(advInput1); }else if (mode.equals("2")){ double advInput2 = Console.getDoubleInput("Enter the exponent value: "); advAnswer = advCalc.exponent(advInput1,advInput2); }else if (mode.equals("3")){ advAnswer = advCalc.inverse(advInput1); }else if (mode.equals("4")){ advAnswer = advCalc.opposite(advInput1); }else if (mode.equals("5")){ advAnswer = advCalc.absoluteValue(advInput1); }else if (mode.equals("6")){ advAnswer = advCalc.sqrt(advInput1); }else if (mode.equals("7")) { break; }else{ Console.println("Invalid input"); } Console.println(Double.toString(advAnswer)); break; case "3": // Sends to Scientific Calculator Functions // displays the menu for scientific calc scientificCalc.toSciMenu(); String sciMenuInput = Console.getStringInput("Enter the function you'd like to use by key."); // if statement to use various calc functions if (sciMenuInput.equals("1")) { // Base Conversions // while loop for display String baseMode = ""; baseChange.switchDisplay(); baseMode = Console.getStringInput("Enter the desired display mode: "); int userInput = getIntegerInput("Enter the number you want to convert to selected base: "); String baseOutput = baseChange.switchDisplayOutput(baseMode, userInput); Console.println(baseOutput); break; // display mode // gets mode // asks for input } else if (sciMenuInput.equals("2")) { // Memory memory.memoryMenu(); } else if (sciMenuInput.equals("3")) { // To Trig Menu trigMenu.trigFunctions(); String trigMode = Console.getStringInput("Enter trignometric function by key: (ie. 1 for sin)"); double trigInput = Console.getDoubleInput("Enter the input for the trignometric function: "); double trigAnswer = 0; if (trigMode.equals("1")) { trigAnswer = trigMenu.calcSin(trigInput); //COS } else if (trigMode.equals("2")) { trigAnswer = trigMenu.calcCos(trigInput); //TAN } else if (trigMode.equals("3")) { trigAnswer = trigMenu.calcTan(trigInput); //ARCSIN } else if (trigMode.equals("4")) { trigAnswer = trigMenu.calcArcsin(trigInput); //ARCCOS } else if (trigMode.equals("5")) { trigAnswer = trigMenu.calcArccos(trigInput); //ARCTAN } else if (trigMode.equals("6")) { trigAnswer = trigMenu.calcArctan(trigInput); } else if (trigMode.equals("7")) { break; } else { //Error message if input does not match options, loops back to the top so they can try again. trigAnswer = Double.NaN; } String trigAnswerString = Double.toString(trigAnswer); Console.println(trigAnswerString); String trigDefRad = Console.getStringInput("Do you want to convert your answer from radians to degrees?" + "\nEnter Y or N").toLowerCase(); if (trigDefRad.equals("y") ) { double convertAnswer = trigMenu.toDegrees(trigAnswer); Console.println(Double.toString(convertAnswer)); } break; } else { break; } break; case "4": // Quits the calculator break; } } } public static void print(String output, Object... args) { System.out.printf(output, args); } public static void println(String output, Object... args) { print(output + "\n", args); } public static String getStringInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); String userInput = scanner.nextLine(); return userInput; } public static Integer getIntegerInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); Integer userInput = scanner.nextInt(); return userInput; } public static Double getDoubleInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); Double userInput = scanner.nextDouble(); return userInput; } }