123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. Scanner scan = new Scanner(System.in);
  11. protected static boolean isError = false;
  12. protected static double currentNumber;
  13. protected double numInMemory;
  14. protected double firstNumber;
  15. protected double secondNumber;
  16. /**
  17. * Constructor for objects of class Operations
  18. */
  19. public Operations()
  20. {
  21. // initialise instance variables
  22. }
  23. public double getCurrentNumber() {
  24. return currentNumber;
  25. }
  26. public void display() {
  27. System.out.println(currentNumber);
  28. }
  29. public void update(double z) {
  30. System.out.println(z);
  31. currentNumber = z;
  32. }
  33. public void clear() {
  34. currentNumber = 0;
  35. System.out.println(currentNumber);
  36. isError = false;
  37. }
  38. public void remember() {
  39. numInMemory = currentNumber;
  40. System.out.println("Stored : " + numInMemory);
  41. }
  42. public void recall() {
  43. System.out.println("Stored value: " + numInMemory);
  44. currentNumber = numInMemory;
  45. }
  46. public void invertSign() {
  47. if (currentNumber == 0) {
  48. currentNumber = 0;
  49. update(currentNumber);
  50. } else if (currentNumber > 0){
  51. currentNumber -= (2 * currentNumber);
  52. update(currentNumber);
  53. } else {
  54. currentNumber += (-2 * currentNumber);
  55. update(currentNumber);
  56. }
  57. }
  58. public void addToNumInMemory() {
  59. numInMemory += currentNumber;
  60. System.out.println("Stored value: " + numInMemory);
  61. }
  62. public void switchDisplayMode() {
  63. System.out.print("Binary : 'Y' or 'N'");
  64. String choice = scan.next();
  65. if (choice.equalsIgnoreCase("Y")) {
  66. int binary = (int)currentNumber;
  67. System.out.println(Integer.toBinaryString(binary));
  68. } else if (choice.equalsIgnoreCase("N")) {
  69. System.out.println("Octal: 'Y' or 'N'");
  70. choice = scan.next();
  71. if (choice.equalsIgnoreCase("Y")) {
  72. } else if (choice.equalsIgnoreCase("N")) {
  73. System.out.println("Decimal: 'Y'or 'N'");
  74. choice = scan.next();
  75. if (choice.equalsIgnoreCase("Y")) {
  76. } else if (choice.equalsIgnoreCase("N")) {
  77. System.out.println("Hexadecimal: 'Y' or 'N'");
  78. choice = scan.next();
  79. if (choice.equalsIgnoreCase("Y")) {
  80. } else if (choice.equalsIgnoreCase("N")) {
  81. System.out.println(currentNumber);
  82. }
  83. }
  84. }
  85. }
  86. }
  87. public void switchUnitsMode() {
  88. System.out.print("Degrees : 'Y' or 'N'");
  89. String choice = scan.next();
  90. if (choice.equalsIgnoreCase("Y")) {
  91. double degree = Math.toDegrees(currentNumber);
  92. double regular = currentNumber;
  93. update(degree);
  94. } else if (choice.equalsIgnoreCase("N")) {
  95. System.out.println("Radians: 'Y' or 'N'");
  96. choice = scan.next();
  97. if (choice.equalsIgnoreCase("Y")) {
  98. double radians = Math.toRadians(currentNumber);
  99. double regular = currentNumber;
  100. update(radians);
  101. } else if (choice.equalsIgnoreCase("N")) {
  102. System.out.print(currentNumber);
  103. }
  104. }
  105. }
  106. }