123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. TrigFeatures switchTrigFeatures = new TrigFeatures();
  9. ScientificFeatures switchScientificFeatures = new ScientificFeatures();
  10. //User instructions
  11. String userInput = Console.getStringInput("Choose a symbol or code for the corresponding function: " + "\n"+
  12. "'+' = addition \n"+
  13. "'-' = subtraction \n" +
  14. "'*' = multiplication \n" +
  15. "'/' = division \n" +
  16. "'^' = square \n" +
  17. "'^/' = square root \n" +
  18. "'-/' = switch sign \n" +
  19. "'off' = turns calculator off \n\n");
  20. switch(userInput){
  21. case "+":
  22. double userInput2 = Console.getDoubleInput("Enter number to be added. ");
  23. Console.result = switchCoreFeatures.addNumbers(Console.result, userInput2);
  24. System.out.println(Console.result);
  25. break;
  26. case "-":
  27. double userInput3 = Console.getDoubleInput("Enter number to be subtracted. ");
  28. Console.result = switchCoreFeatures.subtractNumbers(Console.result, userInput3);
  29. System.out.println(Console.result);
  30. break;
  31. case "*":
  32. double userInput4 = Console.getDoubleInput("Enter number to be multiplied. ");
  33. Console.result = switchCoreFeatures.multiplyNumbers(Console.result, userInput4);
  34. System.out.println(Console.result);
  35. break;
  36. case "/":
  37. double userInput5 = Console.getDoubleInput("Enter number to be divided. ");
  38. Console.result = switchCoreFeatures.divideNumbers(Console.result, userInput5);
  39. System.out.println(Console.result);
  40. break;
  41. case "^":
  42. double userInput6 = Console.getDoubleInput("Enter number to be squared. ");
  43. Console.result = switchCoreFeatures.squareNumber(userInput6);
  44. System.out.println(Console.result);
  45. break;
  46. case "^/":
  47. double userInput7 = Console.getDoubleInput("Enter number to be squared rooted. ");
  48. Console.result = switchCoreFeatures.squareRoot(userInput7);
  49. System.out.println(Console.result);
  50. break;
  51. case "-/":
  52. double userInput8 = Console.getDoubleInput("Enter number to have its sign switched. ");
  53. Console.result = switchCoreFeatures.switchSign(userInput8);
  54. System.out.println(Console.result);
  55. break;
  56. case "/x":
  57. double userInput9 = Console.getDoubleInput("Enter number to be inversed. ");
  58. Console.result = switchCoreFeatures.inverseNumber(userInput9);
  59. System.out.println(Console.result);
  60. break;
  61. case "sin":
  62. double userInput10 = Console.getDoubleInput("Enter number to get the sine of. ");
  63. Console.result = switchTrigFeatures.sin(userInput10);
  64. System.out.println(Console.result);
  65. break;
  66. case "inverseSin":
  67. double userInput11 = Console.getDoubleInput("Inverse the sine of. ");
  68. Console.result = switchTrigFeatures.inverseSin(userInput11);
  69. System.out.println(Console.result);
  70. break;
  71. case "cos":
  72. double userInput12 = Console.getDoubleInput("Enter number to get the cosine of. ");
  73. Console.result = switchTrigFeatures.cos(userInput12);
  74. System.out.println(Console.result);
  75. break;
  76. case "inverseCos":
  77. double userInput13 = Console.getDoubleInput("Inverse the cosine of. ");
  78. Console.result = switchTrigFeatures.inverseCos(userInput13);
  79. System.out.println(Console.result);
  80. break;
  81. case "tan":
  82. double userInput14 = Console.getDoubleInput("Enter number to get the tangent of. ");
  83. Console.result = switchTrigFeatures.tan(userInput14);
  84. System.out.println(Console.result);
  85. break;
  86. case "inverseTan":
  87. double userInput15 = Console.getDoubleInput("Inverse the tangent of. ");
  88. Console.result = switchTrigFeatures.inverseTan(userInput15);
  89. System.out.println(Console.result);
  90. break;
  91. case"radians":
  92. double userInput16 = Console.getDoubleInput("Enter number to convert to radians. ");
  93. Console.result = switchTrigFeatures.radians(userInput16);
  94. System.out.println(Console.result);
  95. break;
  96. case"degrees":
  97. double userInput17 = Console.getDoubleInput("Enter number to convert to degrees. ");
  98. Console.result = switchTrigFeatures.degrees(userInput17);
  99. System.out.println(Console.result);
  100. break;
  101. case "logarithm":
  102. double userInput18 = Console.getDoubleInput("Enter number to take the logarithm of. ");
  103. Console.result = switchScientificFeatures.logarithm(userInput18);
  104. System.out.println(Console.result);
  105. break;
  106. case "clear":
  107. Console.clearCalculator = true;
  108. break;
  109. case "off":
  110. Console.calcRunning = false;
  111. break;
  112. /*case "m":
  113. Console.result = CoreFeatures.m;
  114. System.out.println("Number has been saved to 'm'");
  115. Console.result = 0;
  116. }*/
  117. }}
  118. public static void main(String[] args) {
  119. Console.println("Welcome to my calculator!");
  120. MainApplication mainApplication = new MainApplication();
  121. //String s = Console.getStringInput("Enter a string");
  122. //Integer i = Console.getIntegerInput("Enter an integer");
  123. //Double d = Console.getDoubleInput("Enter a double.");
  124. while (Console.calcRunning){
  125. //some sort of commads that take user input for a number
  126. mainApplication.commandCenter();
  127. }
  128. }
  129. }