/** * CS1312 Lab #17 - The Model. *
* Calculator.java - A basic calculator. * * Revisions: 1.1 Mar. 14, 2001 * Added minor modifications to calculation behavior. Added * some documentation. * 1.0 Jan. 11, 2001 * Created the Calculator class * ** * @author Luke A. Olbrish * @version Version 1.1, Mar. 14, 2001 */ public class Calculator { // Constants /** * This constant denotes the use of the clear operation. */ public static final int CLR_OP = 0; /** * This constant denotes the computation operation. */ public static final int EQL_OP = 1; /** * This constant denotes that addition should be used. * * @see #DIV_OP * @see #MUL_OP * @see #SUB_OP */ public static final int ADD_OP = 2; /** * This constant denotes that subtraction should be used. * * @see #ADD_OP * @see #DIV_OP * @see #MUL_OP */ public static final int SUB_OP = 3; /** * This constant denotes that multiplication should be used. * * @see #ADD_OP * @see #DIV_OP * @see #SUB_OP */ public static final int MUL_OP = 4; /** * This constant denotes that division should be used. * * @see #ADD_OP * @see #MUL_OP * @see #SUB_OP */ public static final int DIV_OP = 5; // Data Block /** * Status variable that determines if operator1 is in an initialized form. * * @see #isOperator2Set * @see #operator1 */ private boolean isOperator1Set = false; /** * The value of the first operator. * * @see #isOperator1Set * @see #operator2 */ private int operator1 = Integer.MIN_VALUE; /** * Status variable that determines if operator2 is in an initialized form. * * @see #isOperator1Set * @see #operator2 */ private boolean isOperator2Set = false; /** * The value of the second operator. * * @see #isOperator2Set * @see #operator1 */ private int operator2 = Integer.MIN_VALUE; /** * Status variable that determines if the operation is in an initialized * form. * * @see #operation */ private boolean isOperationSet = false; /** * The value of the math operation. * * @see #isOperationSet */ private int operation = Integer.MIN_VALUE; // Accessors /** * Reports whether the operation has been set yet. * * @see #isOperator1Set * @see #isOperator2Set */ public boolean isOperationSet() { return this.isOperationSet; }// end of isOperationSet() /** * Reports whether operation 1 has been set yet. * * @see #isOperationSet * @see #isOperator2Set */ public boolean isOperator1Set() { return this.isOperator1Set; }// end of isOperator1Set() /** * Reports whether operation 2 has been set yet. * * @see #isOperationSet * @see #isOperator1Set */ public boolean isOperator2Set() { return this.isOperator2Set; }// end of isOperator2Set() /** * Gets the calculation of the operators and operation if possible. If * only operator1 is initialized, then operator1 is returned. If * non of the operators or operation are initialized than an Arithmetic * Exception is thrown. *