Class infixModel.InfixCalc


public class InfixCalc
extends Object
Represents the calculator itself, without its GUI and separate from its states. Copyright (C) 2004 Dung X. Nguyen. All rights Reserved.


Variable Index

 o _acc
accumulated computation
 o _curState
The current state
 o _display
current display string
 o _noOp
A no-op
 o _pendingOp
Current pending operation

Constructor Index

 o InfixCalc ()
Inialize this Calculator to the "clear" state

Method Index

 o clear ()
Set this Calculator to the "clear" state where all internal memories are
 o enterDigit (char)
Enters a digit
 o enterEqual ()
Compute the current operation and return the result String
 o enterOp (IBinOp)
Perform the pending operation, and prepare to add whatever is computed so
 o enterPoint ()
Enters a decimal point
 o getAcc ()
Gets the current accumulator value
 o getCurState ()
Get the current state
 o getDisplay ()
Get the current display string
 o getPendingOp ()
Get the pending operation
 o setAcc (double)
Sets the accumulator value
 o setCurState (ACalcState)
Sets the current state
 o setDisplay (String)
Sets the display string
 o setNoOp ()
Sets the pending operation to a no-op
 o setPendingOp (IBinOp)
Sets the pending operation

Variables

 o _acc
private double _acc
accumulated computation

 o _display
private String _display
current display string

 o _pendingOp
private IBinOp _pendingOp
Current pending operation

 o _noOp
private final IBinOp _noOp = new IBinOp() {
    public double compute(double n1, double n2) {
      return Double.parseDouble(_display);
    }
  }
A no-op

 o _curState
private ACalcState _curState
The current state

Constructors

 o InfixCalc
public  InfixCalc()
Inialize this Calculator to the "clear" state.

Methods

 o enterDigit
public final String enterDigit(char c)
Enters a digit.

Parameters:
c - '0' <= c <= '9'.
Returns:
accumulated input.
 o enterPoint
public final String enterPoint()
Enters a decimal point

 o enterOp
public final String enterOp(IBinOp op)
Perform the pending operation, and prepare to add whatever is computed so far to the operand that will be entered next and return the resulting String.

Parameters:
op - The new pending operation.
 o enterEqual
public final String enterEqual()
Compute the current operation and return the result String.

 o clear
public final String clear()
Set this Calculator to the "clear" state where all internal memories are set to zero and the pending operation is a no-op.

 o getAcc
final double getAcc()
Gets the current accumulator value

Returns:
The current accumulator value
 o setAcc
final void setAcc(double a)
Sets the accumulator value

Parameters:
a - The new accumulator value
 o setDisplay
final void setDisplay(String d)
Sets the display string

Parameters:
d - The new display string
 o getDisplay
final String getDisplay()
Get the current display string

Returns:
The current display string
 o setPendingOp
final void setPendingOp(IBinOp op)
Sets the pending operation

Parameters:
op - The new pending operation
 o getPendingOp
final IBinOp getPendingOp()
Get the pending operation *

Returns:
The pending operation
 o setNoOp
final void setNoOp()
Sets the pending operation to a no-op

 o setCurState
final void setCurState(ACalcState curState)
Sets the current state.

Parameters:
curState - The new current state
 o getCurState
final ACalcState getCurState()
Get the current state

Returns:
The current state