123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import java.util.*;
  2. import java.lang.*;
  3. /**
  4. * Created by leon on 2/9/18.
  5. */
  6. public class Console {
  7. //GIVEN TO US
  8. public static void print(String output, Object... args) {
  9. System.out.printf(output, args);
  10. }
  11. //GIVEN TO US
  12. public static void println(String output, Object... args) {
  13. print(output + "\n", args);
  14. }
  15. //GIVEN TO US
  16. public static String getStringInput(String prompt) {
  17. Scanner scanner = new Scanner(System.in);
  18. println(prompt);
  19. String userInput = scanner.nextLine();
  20. return userInput;
  21. }
  22. //GIVEN TO US
  23. public static Integer getIntInput(String prompt) {
  24. Scanner scanner = new Scanner(System.in);
  25. println(prompt);
  26. int userInput = scanner.nextInt();
  27. return userInput;
  28. }
  29. //GIVEN TO US
  30. public static Double getDoubleInput(String prompt) {
  31. Scanner scanner = new Scanner(System.in);
  32. println(prompt);
  33. double userInput = scanner.nextDouble();
  34. return userInput;
  35. }
  36. public static String display(){
  37. //ALWAYS DISPLAY WHATS IN YOUR CALCULATOR ( STRINGBUILDER )
  38. return null;
  39. //return display;
  40. }
  41. // public static double getInput(String numberString){
  42. // //GETS INPUT FROM PERSON ( X )
  43. // //String numberString = getStringInput("Please choose a number.");
  44. // quit(numberString);
  45. // try{
  46. // double number1 = Double.parseDouble(numberString);
  47. // //System.out.println(number1);
  48. // return number1;
  49. // }catch(Exception e){
  50. // return getInput(numberString);
  51. // }
  52. // }
  53. /*
  54. public static double invert(double number){
  55. //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
  56. try{
  57. double invertedNumber = -number;
  58. System.out.println(invertedNumber);
  59. return invertedNumber;
  60. } catch(Exception e){
  61. return getInput();
  62. }
  63. }
  64. */
  65. public static double getNumber(String numberString){
  66. if(numberString.equals("quit") || numberString.equals("reset") || numberString.equals("clear")){
  67. quit(numberString);
  68. simpleOp.currentNumber = 0;
  69. }else if(numberString.equals("pi")){
  70. simpleOp.currentNumber = Math.PI;
  71. }else if(numberString.equals("e")){
  72. simpleOp.currentNumber = Math.E;
  73. }else{
  74. simpleOp.currentNumber = Double.parseDouble(numberString);
  75. }
  76. return simpleOp.currentNumber;
  77. }
  78. public static String getOp(){
  79. //GET OPERATION FROM PERSON
  80. System.out.println("Current Number: " + simpleOp.currentNumber);
  81. String operation = getStringInput("Please choose your operation.");
  82. if (operation == null) {
  83. System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands.");
  84. }
  85. quit(operation);
  86. opSwitch.choose(operation);
  87. //return opSwitch.choose(operation1);
  88. return operation;
  89. }
  90. public static void quit(String answer){
  91. if(answer.equals("quit")){
  92. System.exit(0);
  93. } else if(answer.equals("clear")) {
  94. System.out.print('\f');
  95. } else if(answer.equals("reset")){
  96. simpleOp.currentNumber = 0;
  97. //getNumber(Console.getStringInput("Enter Number."));
  98. }
  99. }
  100. }