|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectca.bcit.cst.comp2526.assign2b.solution.RPNCalculator
public class RPNCalculator
Perform discrete operations on operands stored in a stack. http://en.wikipedia.org/wiki/Reverse_Polish_notation
| Field Summary | |
|---|---|
static int |
MIN_STACK_SIZE
The smallest possible stack size that will still work for an RPN calculator. |
| Constructor Summary | |
|---|---|
RPNCalculator(int stackSize)
Construct an RPNCalculator with the specified stack size. |
|
| Method Summary | |
|---|---|
static Operation |
getOperation(char code)
Get the Operation specified by the code. |
int |
getResult()
Get the current result from the operand stack. |
void |
perform(Operation operation)
Perform the specified operation with the top two values on the operand stack. |
void |
push(int operand)
Push the speicifed operand onto the operand stack. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MIN_STACK_SIZE
| Constructor Detail |
|---|
public RPNCalculator(int stackSize)
stackSize - the number of items on the stack.
java.lang.IllegalArgumentException - if the stackSize < MIN_STACK_SIZE.MIN_STACK_SIZE| Method Detail |
|---|
public void push(int operand)
throws StackOverflowException
operand - the operand to push onto the operand stack.
StackOverflowException - if the operand stack is full.
public int getResult()
throws StackUnderflowException
StackUnderflowException - if the operand stack is empty.
public void perform(Operation operation)
throws StackOverflowException,
StackUnderflowException,
java.lang.IllegalArgumentException
operation - the operation to perform.
StackUnderflowException - if there are less than two operands on the stack.
StackOverflowException - if the result overflows the stack (impoossible to actually occur).
java.lang.IllegalArgumentException - if the operation is null.Operation.getCode()
public static Operation getOperation(char code)
throws InvalidOperationTypeException
code - the type of operation.
InvalidOperationTypeException - if the code does not match an Operation.Operation.getCode()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||