12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import java.lang.Math;
  2. import java.util.*;
  3. /**
  4. * Created by leon on 2/9/18.
  5. */
  6. public class Console {
  7. public static void main(String[] args){
  8. boolean run = true;
  9. double x = 0;
  10. double y = 0;
  11. double answer = 0.0;
  12. Scanner scanObject = new Scanner(System.in);
  13. while (run) {
  14. System.out.println("Enter A number: ");
  15. x = scanObject.nextDouble();
  16. System.out.println("Enter An operation? Choose one below.");
  17. System.out.println("( sin ) ( cos ) ( tan ) ( asin ) ( acos ) ( atan ) ( sqrt ) ");
  18. System.out.println("( + ) ( - ) ( * ) ( / ) ( ^ )");
  19. String operator = scanObject.next();//.charAt(0);
  20. String s = "";
  21. if (operator.equals("sin") || operator.equals("asin") || operator.equals("cos") || operator.equals("acos") || operator.equals("tan") || operator.equals("atan") || operator.equals("sqrt")) {
  22. switch (operator){
  23. case "sin": answer = Math.toDegrees(Math.sin(x));
  24. break;
  25. case "asin": answer = Math.toDegrees(Math.asin(x));
  26. break;
  27. case "cos": answer = Math.toDegrees(Math.cos(x));
  28. break;
  29. case "acos": answer = Math.toDegrees(Math.acos(x));
  30. break;
  31. case "tan": answer = Math.toDegrees(Math.tan(x));
  32. break;
  33. case "atan": answer = Math.toDegrees(Math.atan(x));
  34. break;
  35. case "sqrt": answer = Math.toDegrees(Math.sqrt(x));
  36. break;
  37. //case "!": answer = factorial(x);
  38. //break;
  39. }
  40. System.out.println(Math.toRadians(answer));
  41. continue;
  42. } else
  43. System.out.println("Enter A second number: ");
  44. y = scanObject.nextDouble();
  45. s = scanObject.nextLine();
  46. switch (operator) {
  47. case "+": answer = x + y;
  48. break;
  49. case "-": answer = x - y;
  50. break;
  51. case "*": answer = x * y;
  52. break;
  53. case "/": answer = x/y;
  54. break;
  55. case "^": answer = Math.pow (x,y);
  56. break;
  57. }
  58. System.out.println(x + " " + operator + " " + y + " = " + answer);
  59. System.out.println("Continue or Quit");
  60. s = scanObject.nextLine();
  61. if (s.equalsIgnoreCase("Quit")){
  62. System.out.println("Have A good day!! :) ");
  63. break;
  64. }
  65. }
  66. }
  67. }