123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /**
- *
- * Allison & Alfredo
- * 5/25/2018
- *
- */
-
-
- public class Calculator
- {
- private double displayValue;
- private double memoryValue;
-
- /**
- * Constructor for objects of class Calculator
- */
- public Calculator()
- {
- displayValue = 0;
- memoryValue = 0;
- }
-
- //Memory set
- public double memSet(){
- memoryValue = displayValue;
- return memoryValue;
- }
-
- public double memClear(){
- memoryValue = 0;
- return memoryValue;
- }
-
- public double mrc(){
- displayValue = memoryValue;
- return displayValue;
- }
-
- public double getMem() {
- return memoryValue;
- }
-
- //Clear and retrieve display value
- public double clear(){
- displayValue = 0;
- return displayValue;
- }
-
- public double setDisplayValue(double value){
- displayValue = value;
- return displayValue;
- }
-
- public double getDisplayValue(){
- return displayValue;
- }
-
- //basic functions
- public double add(double value){
- displayValue += value;
- return displayValue;
- }
-
- public double subtract(double value){
- displayValue -= value;
- return displayValue;
- }
-
- public double multiply(double value){
- displayValue *= value;
- return displayValue;
- }
-
- public double divide(double divisor){
- displayValue = displayValue / divisor;
- return displayValue;
- }
-
- public double pow(double exponent){
- displayValue = Math.pow(displayValue, exponent);
- return displayValue;
- }
-
- public double square(){
- return pow(2);
- }
-
- public double squareRoot(){
- displayValue = Math.sqrt(displayValue);
- return displayValue;
- }
-
- public double inverse(){
- displayValue = 1 / displayValue;
- return displayValue;
- }
-
- public double changeSign(){
- return multiply(-1);
- }
-
- //scientific functions
- public double sin(double val){
- displayValue = Math.sin(val);
- return displayValue;
- }
-
- public double cos(double val) {
- displayValue = Math.cos(val);
- return displayValue;
- }
-
- public double tan(double val) {
- displayValue = Math.tan(val);
- return displayValue;
- }
-
- public double inverseSin(double val) {
- displayValue = Math.asin(val);
- return displayValue;
- }
-
- public double inverseCos(double val) {
- displayValue = Math.acos(val);
- return displayValue;
- }
-
- public double inverseTan(double val) {
- displayValue = Math.atan(val);
- return displayValue;
- }
-
- //Bonus Functions
- public double log() {
- displayValue = Math.log(displayValue);
- return displayValue;
- }
-
- public double inverseLog(){
- displayValue = Math.pow(displayValue, 10);
- return displayValue;
- }
-
- public double naturalLog() {
- displayValue = Math.log1p(displayValue);
- return displayValue;
- }
-
- public double inverseLn() {
- displayValue = Math.pow(Math.E, displayValue);
- return displayValue;
- }
-
- public double factorial() {
- displayValue = (int) displayValue;
- double d = displayValue;
- for (int i = 1; i < d; i++) {
- displayValue = displayValue*i;
- }
- return displayValue;
- }
-
- //Custom functions
- public double displayPi() {
- displayValue = Math.PI;
- return displayValue;
- }
-
- public double displayE(){
- displayValue = Math.E;
- return Math.E;
- }
-
- }
|