MainApplication.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * Created by leon on 2/9/18.
  3. */
  4. public class MainApplication {
  5. private void commandCenter(){
  6. //All the different feature objects
  7. CoreFeatures switchCoreFeatures = new CoreFeatures();
  8. //User instructions
  9. String userInput = Console.getStringInput("Choose a symbol for the corresponding function: " + "\n"+
  10. "'+' = addition \n"+
  11. "'-' = subtraction \n" +
  12. "'*' = multiplication \n" +
  13. "'/' = division \n" +
  14. "'^' = square \n" +
  15. "'^/' = square root \n" +
  16. "'-/' = invert sign \n" +
  17. "'off' = turns calculator off \n\n");
  18. switch(userInput){
  19. case "+":
  20. double userInput2 = Console.getDoubleInput("Enter number to be added. ");
  21. Console.result = switchCoreFeatures.addNumbers(Console.result, userInput2);
  22. System.out.println(Console.result);
  23. break;
  24. case "-":
  25. double userInput3 = Console.getDoubleInput("Enter number to be subtracted. ");
  26. Console.result = switchCoreFeatures.subtractNumbers(Console.result, userInput3);
  27. System.out.println(Console.result);
  28. break;
  29. case "*":
  30. double userInput4 = Console.getDoubleInput("Enter number to be multiplied. ");
  31. Console.result = switchCoreFeatures.multiplyNumbers(Console.result, userInput4);
  32. System.out.println(Console.result);
  33. break;
  34. case "/":
  35. double userInput5 = Console.getDoubleInput("Enter number to be multiplied. ");
  36. Console.result = switchCoreFeatures.multiplyNumbers(Console.result, userInput5);
  37. System.out.println(Console.result);
  38. break;
  39. case "^":
  40. double userInput6 = Console.getDoubleInput("Enter number to be squared. ");
  41. Console.result = switchCoreFeatures.squareNumber(userInput6);
  42. System.out.println(Console.result);
  43. break;
  44. case "^/":
  45. double userInput7 = Console.getDoubleInput("Enter number to be squared rooted. ");
  46. Console.result = switchCoreFeatures.squareRoot(userInput7);
  47. System.out.println(Console.result);
  48. break;
  49. case "-/":
  50. double userInput8 = Console.getDoubleInput("Enter number to be inverted. ");
  51. Console.result = switchCoreFeatures.invertSign(userInput8);
  52. System.out.println(Console.result);
  53. break;
  54. case "off":
  55. Console.calcRunning = false;
  56. break;
  57. }
  58. }
  59. public static void main(String[] args) {
  60. Console.println("Welcome to my calculator!");
  61. MainApplication mainApplication = new MainApplication();
  62. //String s = Console.getStringInput("Enter a string");
  63. //Integer i = Console.getIntegerInput("Enter an integer");
  64. //Double d = Console.getDoubleInput("Enter a double.");
  65. while (Console.calcRunning){
  66. //some sort of commads that take user input for a number
  67. mainApplication.commandCenter();
  68. }
  69. }
  70. }