EDU.ksu.cis.calculator.javamodel
Class CalculatorImpl

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

public class CalculatorImpl
extends Object
implements Calculator

A model for an RPN calculator using the BigInteger class.

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

Constructor Summary
CalculatorImpl(CalculatorUI v)
          Constructs a new CalculatorImpl using the given user interface and base 10.
CalculatorImpl(CalculatorUI v, int b)
          Constructs a new CalculatorImpl using the given user interface and base.
 
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 and base 10.


CalculatorImpl

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

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. As there are no settings to change in this model, this method does nothing.

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