Calculator.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. public class Calculator
  2. {
  3. // instance variables - replace the example below with your own
  4. private double displayValue;
  5. private double memoryValue;
  6. <<<<<<< HEAD
  7. //private CoreFeatures core;
  8. //private ScientificFeatures science;
  9. //private BonusFeatures bonus;
  10. =======
  11. private boolean err;
  12. >>>>>>> 85cb6e118e199051f7fc22d59044b58cdf7dcf01
  13. /**
  14. * Constructor for objects of class Calculator
  15. */
  16. public Calculator()
  17. {
  18. displayValue = 0;
  19. memoryValue = 0;
  20. err = false;
  21. }
  22. //Memory set
  23. public double memSet(){
  24. memoryValue = displayValue;
  25. return memoryValue;
  26. }
  27. public double memClear(){
  28. memoryValue = 0;
  29. return memoryValue;
  30. }
  31. public double mrc(){
  32. displayValue = memoryValue;
  33. return displayValue;
  34. }
  35. //Clear and retrieve display value
  36. public double clear(){
  37. displayValue = 0;
  38. err = false;
  39. return displayValue;
  40. }
  41. public double getDisplayValue(){
  42. return displayValue;
  43. }
  44. //basic functions
  45. public double add(double value1, double value2){
  46. displayValue = value1 + value2;
  47. return displayValue;
  48. }
  49. public double subtract(double value1, double value2){
  50. displayValue = value1 - value2;
  51. return displayValue;
  52. }
  53. public double multiply(double value1, double value2){
  54. displayValue = value1 * value2;
  55. return displayValue;
  56. }
  57. public double divide(double dividend, double divisor){
  58. displayValue = dividend / divisor;
  59. return displayValue;
  60. }
  61. public double pow(double base, double exponent){
  62. displayValue = Math.pow(base, exponent);
  63. return displayValue;
  64. }
  65. public double square(double base){
  66. return pow(base, 2);
  67. }
  68. public double squareRoot(double value){
  69. displayValue = Math.sqrt(value);
  70. return displayValue;
  71. }
  72. public double inverse(double value){
  73. displayValue = 1 / value;
  74. return displayValue;
  75. }
  76. public double changeSign(double value){
  77. return multiply(value, -1);
  78. }
  79. //scientific functions
  80. public double sin(double value){
  81. displayValue = Math.sin(value);
  82. return displayValue;
  83. }
  84. public double cos(double value) {
  85. displayValue = Math.cos(value);
  86. return displayValue;
  87. }
  88. public double tan(double value) {
  89. displayValue = Math.tan(value);
  90. return displayValue;
  91. }
  92. public double log(double value) {
  93. displayValue = Math.log(value);
  94. return displayValue;
  95. }
  96. public double inverseSin(double value) {
  97. displayValue = Math.log(value);
  98. return displayValue;
  99. }
  100. public double inverseCos(double value) {
  101. displayValue = Math.acos(value);
  102. return displayValue;
  103. }
  104. public double inverseTan(double value) {
  105. displayValue = Math.atan(value);
  106. return displayValue;
  107. }
  108. public double inverseLog(double value){
  109. displayValue = Math.pow(value, 10);
  110. return displayValue;
  111. }
  112. public double naturalLog(double value) {
  113. displayValue = Math.log1p(value);
  114. return displayValue;
  115. }
  116. public double inverseLn(double value) {
  117. displayValue = Math.pow(Math.E, value);
  118. return displayValue;
  119. }
  120. public double displayPi() {
  121. displayValue = Math.PI;
  122. return displayValue;
  123. }
  124. public double displayE(){
  125. displayValue = Math.E;
  126. return Math.E;
  127. }
  128. }