123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Write a description of class Operations here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.util.Scanner;
  8. public class Operations
  9. {
  10. /**
  11. * prompting a user for a command solving for that command
  12. *
  13. */
  14. public static void printHelp(){
  15. System.out.println("\n? | + | - | * | / |");
  16. System.out.println("^ | sqrt | exp | inverse |");
  17. System.out.println("cos | sine | tan | cos-1 | sin-1 | m+ | m- | MRC");
  18. System.out.println("log | ln | ex |");
  19. System.out.println("to clear display enter clrDisplay\n");
  20. }
  21. public static Double runCommand()
  22. {
  23. // put your code here
  24. Scanner input = new Scanner(System.in);
  25. Double result = 0.0;
  26. //String userInput = scanner.nextLine();
  27. scienticFunctions ScientificFunctions = new scienticFunctions();
  28. Memory memory = new Memory();
  29. DiplayMode displayMode = new DiplayMode();
  30. bonusFunctions bonusFunctions = new bonusFunctions();
  31. // Calculator calc = new ....
  32. while (true) {
  33. System.out.print("Enter a command: ");
  34. String command = input.next();
  35. if (command.equalsIgnoreCase("exit")) {
  36. System.out.print("Thanks for calculating with us!");
  37. break;
  38. }
  39. else if (command.equalsIgnoreCase("sine")) {
  40. if (result != 0){
  41. result = ScientificFunctions.sine(result);
  42. }
  43. else{
  44. result = ScientificFunctions.sine(Console.getDoubleInput("Enter number"));
  45. }
  46. Console.printResult(result);
  47. }
  48. else if (command.equalsIgnoreCase("cos")) {
  49. if (result != 0){
  50. result = ScientificFunctions.cosine(result);
  51. }
  52. else{
  53. result = ScientificFunctions.cosine(Console.getDoubleInput("Enter number"));
  54. }
  55. Console.printResult(result);
  56. }
  57. else if (command.equalsIgnoreCase("tan")) {
  58. if (result != 0){
  59. result = ScientificFunctions.tangent(result);
  60. }
  61. else{
  62. result = ScientificFunctions.tangent(Console.getDoubleInput("Enter number"));
  63. }
  64. Console.printResult(result);
  65. }
  66. else if (command.equalsIgnoreCase("cos-1")) {
  67. if (result != 0){
  68. result = ScientificFunctions.inverseCosine(result);
  69. }
  70. else{
  71. result = ScientificFunctions.inverseCosine(Console.getDoubleInput("Enter number"));
  72. }
  73. Console.printResult(result);
  74. }
  75. else if (command.equalsIgnoreCase("sin-1")) {
  76. if (result != 0){
  77. result = ScientificFunctions.inverseSine(result);
  78. }
  79. else{
  80. result = ScientificFunctions.inverseSine(Console.getDoubleInput("Enter number"));
  81. }
  82. Console.printResult(result);
  83. }
  84. else if (command.equalsIgnoreCase("tan-1")) {
  85. if (result != 0){
  86. result = ScientificFunctions.inverseTangent(result);
  87. }
  88. else{
  89. result = ScientificFunctions.inverseTangent(Console.getDoubleInput("Enter number"));
  90. }
  91. Console.printResult(result);
  92. }
  93. else if(command.equalsIgnoreCase("M+")){
  94. memory.storeInMemory(result);
  95. Console.printResult(result);
  96. }
  97. else if (command.equalsIgnoreCase("M-")){
  98. Console.printResult(memory.clearMemory());
  99. }
  100. else if (command.equalsIgnoreCase("MRC")){
  101. Console.printResult(memory.retrieveFromMemory());
  102. }
  103. else if (command.equalsIgnoreCase("switchmode")){
  104. displayMode.setResult(result);
  105. String mode = displayMode.enterMode();
  106. //System.out.println(mode);
  107. displayMode.switchDisplayMode(mode);
  108. }
  109. else if (command.equalsIgnoreCase("log")){
  110. Console.printResult(bonusFunctions.LogBaseTenOfAnumber(result));
  111. }
  112. else if (command.equalsIgnoreCase("ln")){
  113. Console.printResult(bonusFunctions.naturalLogLn(result));
  114. }
  115. else if (command.equalsIgnoreCase("ex")){
  116. Console.printResult(bonusFunctions.exponential(result));
  117. }
  118. else if(command.equalsIgnoreCase("?")){
  119. printHelp();
  120. }
  121. else if(command.equalsIgnoreCase("clrDisplay")){
  122. result = 0.0;
  123. }
  124. else{
  125. Console.println("Invalid command please press ? for help");
  126. }
  127. //firstNumber = result;
  128. // and on and on
  129. }
  130. return result;
  131. }
  132. //Add CommentCollapse 
  133. }