import java.util.*; import java.lang.*; /** * Created by leon on 2/9/18. */ public class Console { public static double currentNumber = 0; public static String regexNum = "\\d+(?:\\.\\d+)?"; //GIVEN TO US public static void print(String output, Object... args) { System.out.printf(output, args); } //GIVEN TO US public static void println(String output, Object... args) { print(output + "\n", args); } //GIVEN TO US public static String getStringInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); String userInput = scanner.nextLine(); return userInput; } //GIVEN TO US public static Integer getIntInput(String prompt) { Scanner scanner = new Scanner(System.in); println(prompt); int userInput = scanner.nextInt(); return userInput; } //GIVEN TO US 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 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 void getInput() { System.out.println(currentNumber); String input = getStringInput("Please enter an operation or number. Enter '?' for a list of commands."); quit(input); if (input.matches(regexNum) || input.charAt(0) == '.' || input.equals("pi") || input.equals("e")) { getNumber(input); } else { getOp(input); } } public static double getNumber(String numberString){ if(numberString.equals("quit") || numberString.equals("reset") || numberString.equals("clear")){ quit(numberString); currentNumber = 0; }else if(numberString.equals("pi")){ currentNumber = Math.PI; }else if(numberString.equals("e")){ currentNumber = Math.E; }else{ currentNumber = Double.parseDouble(numberString); } return currentNumber; } public static String getOp(String operation){ //GET OPERATION FROM PERSON //System.out.println(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."); } else { //quit(operation); opSwitch.choose(operation); //return opSwitch.choose(operation1); } return operation; } public static void quit(String answer){ if(answer.equals("quit")){ System.exit(0); } else if(answer.equals("clear")) { System.out.print('\f'); } else if(answer.equals("reset")){ currentNumber = 0; //getNumber(Console.getStringInput("Enter Number.")); } } }