123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * A class to define math opeerations for the
  3. * Calculator
  4. */
  5. import java.lang.Math;
  6. public class BasicCalculations extends Operations
  7. {
  8. private int x;
  9. /**
  10. * Constructor for objects of class BasicCalculations
  11. */
  12. public BasicCalculations()
  13. {
  14. // initialise instance variables
  15. x = 0;
  16. }
  17. /**
  18. * An example of a method - replace this comment with your own
  19. *
  20. * @param y a sample parameter for a method
  21. * @return the sum of x and y
  22. */
  23. public double sampleMethod(double y)
  24. {
  25. // put your code here
  26. return x + y;
  27. }
  28. public void add(double x, double y)
  29. {
  30. double z = x + y;
  31. update(z);
  32. }
  33. public double subtract(double x, double y)
  34. {
  35. double z = x - y;
  36. update(z);
  37. return z;
  38. }
  39. public double multiply(double x, double y)
  40. {
  41. double z = x * y;
  42. update(z);
  43. return z;
  44. }
  45. public void divide(double x, double y)
  46. {
  47. if (y == 0){
  48. System.out.println("Error");
  49. isError = true;
  50. } else {
  51. double z = (x / y);
  52. update(z);
  53. }
  54. }
  55. public void square(double x){
  56. double z = x * x;
  57. update(z);
  58. }
  59. public void squareRoot (double x){
  60. double z = Math.sqrt(x);
  61. update(z);
  62. }
  63. public void power(double x,double y){
  64. double z = Math.pow(x,y);
  65. update(z);
  66. }
  67. public void sin(double x){
  68. double z = Math.sin(x);
  69. update(z);
  70. }
  71. public void cos(double x){
  72. double z = Math.cos(x);
  73. update(z);
  74. }
  75. public void tan(double x){
  76. double z = Math.tan(x);
  77. update(z);
  78. }
  79. public void degrees(double x){
  80. double z = Math.toDegrees(x);
  81. update(z);
  82. }
  83. public void radians(double x){
  84. double z = Math.toRadians(x);
  85. update(z);
  86. }
  87. public void atan(double x){
  88. double z = Math.atan(x);
  89. update(z);
  90. }
  91. public void acos(double x){
  92. double z = Math.acos(x);
  93. update(z);
  94. }
  95. public void asin(double x){
  96. double z = Math.asin(x);
  97. update(z);
  98. }
  99. public void log(double x){
  100. double z = Math.log10(x);
  101. update(z);
  102. }
  103. public void round(double x) {
  104. double z = Math.round(x);
  105. update(z);
  106. }
  107. public void roundUp(double x) {
  108. double z = Math.ceil(x);
  109. update(z);
  110. }
  111. public void roundDown(double x) {
  112. double z = Math.floor(x);
  113. update(z);
  114. }
  115. public void inverse(double x) {
  116. double z = (1/x);
  117. update(z);
  118. }
  119. }