123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. *
  3. * Allison & Alfredo
  4. * 5/25/2018
  5. *
  6. */
  7. public class Calculator
  8. {
  9. private double displayValue;
  10. private double memoryValue;
  11. /**
  12. * Constructor for objects of class Calculator
  13. */
  14. public Calculator()
  15. {
  16. displayValue = 0;
  17. memoryValue = 0;
  18. }
  19. //Memory set
  20. public double memSet(){
  21. memoryValue = displayValue;
  22. return memoryValue;
  23. }
  24. public double memClear(){
  25. memoryValue = 0;
  26. return memoryValue;
  27. }
  28. public double mrc(){
  29. displayValue = memoryValue;
  30. return displayValue;
  31. }
  32. public double getMem() {
  33. return memoryValue;
  34. }
  35. //Clear and retrieve display value
  36. public double clear(){
  37. displayValue = 0;
  38. return displayValue;
  39. }
  40. public double setDisplayValue(double value){
  41. displayValue = value;
  42. return displayValue;
  43. }
  44. public double getDisplayValue(){
  45. return displayValue;
  46. }
  47. //basic functions
  48. public double add(double value){
  49. displayValue += value;
  50. return displayValue;
  51. }
  52. public double subtract(double value){
  53. displayValue -= value;
  54. return displayValue;
  55. }
  56. public double multiply(double value){
  57. displayValue *= value;
  58. return displayValue;
  59. }
  60. public double divide(double divisor){
  61. displayValue = displayValue / divisor;
  62. return displayValue;
  63. }
  64. public double pow(double exponent){
  65. displayValue = Math.pow(displayValue, exponent);
  66. return displayValue;
  67. }
  68. public double square(){
  69. return pow(2);
  70. }
  71. public double squareRoot(){
  72. displayValue = Math.sqrt(displayValue);
  73. return displayValue;
  74. }
  75. public double inverse(){
  76. displayValue = 1 / displayValue;
  77. return displayValue;
  78. }
  79. public double changeSign(){
  80. return multiply(-1);
  81. }
  82. //scientific functions
  83. public double sin(double val){
  84. displayValue = Math.sin(val);
  85. return displayValue;
  86. }
  87. public double cos(double val) {
  88. displayValue = Math.cos(val);
  89. return displayValue;
  90. }
  91. public double tan(double val) {
  92. displayValue = Math.tan(val);
  93. return displayValue;
  94. }
  95. public double inverseSin(double val) {
  96. displayValue = Math.asin(val);
  97. return displayValue;
  98. }
  99. public double inverseCos(double val) {
  100. displayValue = Math.acos(val);
  101. return displayValue;
  102. }
  103. public double inverseTan(double val) {
  104. displayValue = Math.atan(val);
  105. return displayValue;
  106. }
  107. //Bonus Functions
  108. public double log() {
  109. displayValue = Math.log(displayValue);
  110. return displayValue;
  111. }
  112. public double inverseLog(){
  113. displayValue = Math.pow(displayValue, 10);
  114. return displayValue;
  115. }
  116. public double naturalLog() {
  117. displayValue = Math.log1p(displayValue);
  118. return displayValue;
  119. }
  120. public double inverseLn() {
  121. displayValue = Math.pow(Math.E, displayValue);
  122. return displayValue;
  123. }
  124. public double factorial() {
  125. displayValue = (int) displayValue;
  126. double d = displayValue;
  127. for (int i = 1; i < d; i++) {
  128. displayValue = displayValue*i;
  129. }
  130. return displayValue;
  131. }
  132. //Custom functions
  133. public double displayPi() {
  134. displayValue = Math.PI;
  135. return displayValue;
  136. }
  137. public double displayE(){
  138. displayValue = Math.E;
  139. return Math.E;
  140. }
  141. }