// CalcModel.java // Fred Swartz - December 2004 // Paolo Bucci -- November 2009 (modified) // Model // This model is completely independent of the user interface. // It could as easily be used by a command line or web interface. import java.math.BigInteger; public class CalcModel { // ... Constants private static final String INITIAL_VALUE = "1"; // identity for multiply // ... Member variable defining state of calculator. private BigInteger m_total; // The total current value state. // ============================================================== // constructor /** Constructor */ public CalcModel() { this.reset(); } // ==================================================================== // reset /** Reset to initial value. */ public void reset() { this.m_total = new BigInteger(INITIAL_VALUE); } // =============================================================== // multiplyBy /** * Multiply current total by a number. * * @param operand * Number (as string) to multiply total by. */ public void multiplyBy(String operand) { this.m_total = this.m_total.multiply(new BigInteger(operand)); } // ================================================================= // setValue /** * Set the total value. * * @param value * New value that should be used for the calculator total. */ public void setValue(String value) { this.m_total = new BigInteger(value); } // ================================================================= // getValue /** Return current calculator total. */ public String getValue() { return this.m_total.toString(); } }