123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // instance variables - replace the example below with your own
  11. private int x;
  12. scienticFunctions scientificOperator = new scienticFunctions();
  13. /**
  14. * Constructor for objects of class Operations
  15. */
  16. public Operations()
  17. {
  18. // initialise instance variables
  19. //x = 0;
  20. }
  21. /**
  22. * An example of a method - replace this comment with your own
  23. *
  24. * @param y a sample parameter for a method
  25. * @return the sum of x and y
  26. */
  27. public static void runCommand()
  28. {
  29. // put your code here
  30. Scanner input = new Scanner(System.in);
  31. Double result = 0.0;
  32. double firstNumber = 0.0;
  33. double SecondNumber =0.0;
  34. //String userInput = scanner.nextLine();
  35. scienticFunctions ScientificFunctions = new scienticFunctions();
  36. // Calculator calc = new ....
  37. while (true) {
  38. System.out.print("Enter a command: ");
  39. String command = input.next();
  40. if (command.equalsIgnoreCase("exit")) {
  41. System.out.print("Thanks for calculating with us!");
  42. break;
  43. }
  44. if (command.equalsIgnoreCase("sine")) {
  45. // read first number
  46. System.out.print("Enter a number: ");
  47. firstNumber = input.nextDouble();
  48. // read second number
  49. //double secondNumber = input.nextDouble();
  50. // call the add method on calc and display
  51. result = ScientificFunctions.sine(firstNumber);
  52. //firstNumber = result;
  53. //result = firstNumber;
  54. Console.printResult(result);
  55. }
  56. if (command.equalsIgnoreCase("cos")) {
  57. // read first number
  58. firstNumber = input.nextDouble();
  59. // call the cosine method on calc and display
  60. result = ScientificFunctions.cos(firstNumber);
  61. Console.printResult(result);
  62. }
  63. if (command.equalsIgnoreCase("tan")) {
  64. // call the square method on calc and display
  65. firstNumber = input.nextDouble();
  66. result = ScientificFunctions.tangent(firstNumber);
  67. Console.printResult(result);
  68. }
  69. if (command.equalsIgnoreCase("cos-1")) {
  70. // call the square method on calc and display
  71. firstNumber = input.nextDouble();
  72. result = ScientificFunctions.inverseCosine(firstNumber);
  73. Console.printResult(result);
  74. }
  75. if (command.equalsIgnoreCase("sin-1")) {
  76. // call the square method on calc and display
  77. firstNumber = input.nextDouble();
  78. result = ScientificFunctions.inverseSine(firstNumber);
  79. Console.printResult(result);
  80. }
  81. if (command.equalsIgnoreCase("tan-1")) {
  82. // call the square method on calc and display
  83. firstNumber = input.nextDouble();
  84. result = ScientificFunctions.inverseTangent(firstNumber);
  85. Console.printResult(result);
  86. }
  87. firstNumber = result;
  88. // and on and on
  89. }
  90. }
  91. //Add CommentCollapse 
  92. }