package samples.calc;
/* 
 * Sample Calculator class to demonstrate
 * the SAS DATA Step JavaObj
 *
 */

public class Calculator {
	private double memory;
	private boolean memflag;
	
	/*
	 * Basic constructor for Calculator class
	 */
	public Calculator(){
		// initialize memory to zero
		memory = 0;	
		// initialize memory flag to false
		memflag = false;
	}
	
	/*
	 * Return the sum of two double values 
	 */
	public static double add(double x,double y){
		return x + y;
	}
	
	/*
	 * Return the difference of two double values 
	 */
	public static double subtract(double x,double y){
		return x - y;
	}
	
	/*
	 * Return the product of two double values 
	 */
	public static double multiply(double x,double y){
		return x * y;
	}
	
	/*
	 * Return the quotient of two double values 
	 */
	public static double divide(double x,double y){
		return x / y;
	}
	
	/*
	 * Add a double value into memory	 
	 */	
	public void memoryPlus(double x){
		memory += x;
		memflag = true;
	}
	
	/*
	 * Subtract a double value from memory 
	 */
	public void memoryMinus(double x){
		memory -= x;
		memflag = true;
	}
	
	/*
	 * Retrieve the current memory 
	 */
	public double memoryRecall(){
		return memory;
	}	
	
	/*
	 * Clear the memory
	 */
	public void memoryClear(){
		memory = 0;
		memflag = false;		
	}	
	
	public boolean hasMemory(){
		return memflag;
	}
}


