EDU.ksu.cis.calculator.defaultmodel
Class CalculatorImpl

java.lang.Object
  |
  +--EDU.ksu.cis.calculator.defaultmodel.CalculatorImpl
All Implemented Interfaces:
Calculator

public class CalculatorImpl
extends Object
implements Calculator

A model for an RPN calculator using the LargeInteger class.

Author:
Rod Howell (howell@cis.ksu.edu)

Constructor Summary
CalculatorImpl(CalculatorUI v)
          Constructs a new CalculatorImpl using the given user interface, base 10, and sticky bases.
CalculatorImpl(CalculatorUI v, boolean s)
          Constructs a new CalculatorImpl using the given user interface and the given setting for sticky bases, in base 10.
CalculatorImpl(CalculatorUI v, int b)
          Constructs a new CalculatorImpl using the given user interface and base, with sticky bases.
CalculatorImpl(CalculatorUI v, int b, boolean s)
          Constructs a new CalculatorImpl using the given user interface, base, and setting for sticky bases.
 
Method Summary
 void changeSettings(Object change, String input)
          Changes the settings of the calculator.
 void doOperation(Operation op, String input)
          Performs the given operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CalculatorImpl

public CalculatorImpl(CalculatorUI v)
Constructs a new CalculatorImpl using the given user interface, base 10, and sticky bases.


CalculatorImpl

public CalculatorImpl(CalculatorUI v,
                      int b)
Constructs a new CalculatorImpl using the given user interface and base, with sticky bases.


CalculatorImpl

public CalculatorImpl(CalculatorUI v,
                      boolean s)
Constructs a new CalculatorImpl using the given user interface and the given setting for sticky bases, in base 10.


CalculatorImpl

public CalculatorImpl(CalculatorUI v,
                      int b,
                      boolean s)
Constructs a new CalculatorImpl using the given user interface, base, and setting for sticky bases.

Method Detail

doOperation

public void doOperation(Operation op,
                        String input)
                 throws EmptyDequeException,
                        NumberFormatException,
                        Exception
Performs the given operation. If input is non-null, it is treated as the top of the stack. If input is "" or "-", it is interpreted as "0". Operands are taken from the top of the stack so that the top element is the last operand. The result (if any) is pushed onto the stack. When the operation is complete, the element that then resides at the top of the stack (if any) is reported to the user interface. If an exception or error is thrown, the stack will be restored to its original contents, if possible.

The following classes of operations are supported:

Specified by:
doOperation in interface Calculator
Throws:
EmptyDequeException - If the operation requires more operands than are present on the stack.
NumberFormatException - If input contains an invalid character for the current base.
Exception - If the given operation throws an exception.

changeSettings

public void changeSettings(Object change,
                           String input)
Changes the settings of the calculator. The only setting that can be changed in this model is sticky bases. If change is of type Boolean, then bases are set to sticky iff the value of change is true. If change is of a different type, this method has no effect. The second parameter is ignored.

Specified by:
changeSettings in interface Calculator
Parameters:
change - Encodes the change to the settings.
input - May contain input affected by the change.