import java.util.*; import java.lang.*; /** * Created by leon on 2/9/18. */ public class Console { 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 getIntInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); int 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; } public static String display(){ //ALWAYS DISPLAY WHATS IN YOUR CALCULATOR ( STRINGBUILDER ) return null; //return display; } public static void clear(){ //CLEARS SCREEN / SET TO ZERO ?? } public static double getInput(String numberString){ //GETS INPUT FROM PERSON ( X ) //String numberString = getStringInput("Please choose a number."); quit(numberString); try{ double number1 = Double.parseDouble(numberString); //System.out.println(number1); return number1; }catch(Exception e){ return getInput(numberString); } } /* public static double invert(double number){ //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE try{ double invertedNumber = -number; System.out.println(invertedNumber); return invertedNumber; } catch(Exception e){ return getInput(); } } */ public static double getNumber(String numberString){ //GETS INPUT FROM PERSON ( Y ) //System.out.println(first + " " + op); //String numberString = getStringInput("Please choose a number."); quit(numberString); try{ double number2 = Double.parseDouble(numberString); //System.out.println(number2); return number2; }catch(Exception e){ return getNumber(numberString); } } public static String getOp(){ //GET OPERATION FROM PERSON System.out.println("Current Number: " + simpleOp.currentNumber); String operation = getStringInput("Please choose your operation."); if (operation == null) { System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands."); } quit(operation); opSwitch.choose(operation); //return opSwitch.choose(operation1); return operation; } public static void quit(String answer){ if(answer.equals("quit") || answer.equals("exit")){ System.exit(0); } else if(answer.equals("clear")) { System.out.print('\f'); } else if(answer.equals("reset")){ simpleOp.currentNumber = 0; System.out.println(simpleOp.currentNumber); } } }