Calculator.java 3.4KB

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