import java.util.*; import java.lang.*; /** * Created by leon on 2/9/18. */ public class Console { //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 double getNumber(String numberString){ if(numberString.equals("quit") || numberString.equals("reset") || numberString.equals("clear")){ quit(numberString); simpleOp.currentNumber = 0; }else if(numberString.equals("pi")){ simpleOp.currentNumber = Math.PI; }else if(numberString.equals("e")){ simpleOp.currentNumber = Math.E; }else{ simpleOp.currentNumber = Double.parseDouble(numberString); } return simpleOp.currentNumber; } 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")){ System.exit(0); } else if(answer.equals("clear")) { System.out.print('\f'); } else if(answer.equals("reset")){ simpleOp.currentNumber = 0; //getNumber(Console.getStringInput("Enter Number.")); } } }