Console.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import java.util.Scanner;
  2. /**
  3. * Created by leon on 2/9/18.
  4. */
  5. public class Console {
  6. public String userInput2;
  7. double currentValue;
  8. double memory;
  9. public Console() {
  10. }
  11. public double getCurrentValue() {
  12. return currentValue;
  13. }
  14. public double clearCurrentValue() {
  15. return currentValue = 0;
  16. }
  17. public double changeCurrentValue(double b) {
  18. return currentValue = b;
  19. }
  20. public double mPlus(double value){
  21. return memory += value;
  22. }
  23. public double mClear(){
  24. return memory = 0;
  25. }
  26. public double mRc(){
  27. return changeCurrentValue(memory);
  28. }
  29. public void print(String output, Object... args) {
  30. System.out.printf(output, args);
  31. }
  32. public void println(String output, Object... args) {
  33. print(output + "\n", args);
  34. }
  35. public String getStringInput(String prompt) {
  36. Scanner scanner = new Scanner(System.in);
  37. println(prompt);
  38. String userInput = scanner.nextLine();
  39. String userInput2 = userInput.toLowerCase();
  40. return userInput2;
  41. }
  42. /*public static Integer getIntegerInput(String prompt) {
  43. return null;
  44. }*/
  45. public Double getDoubleInput(String prompt) {
  46. Scanner scannerB = new Scanner(System.in);
  47. double b = 0;
  48. println(prompt);
  49. if(scannerB.hasNextDouble()){
  50. b = scannerB.nextDouble();
  51. }else{
  52. System.out.print("Invalid input please start over\n");
  53. }
  54. return b;
  55. }
  56. }