Class RPNCalc

java.lang.Object
  |
  +--RPNCalc

public class RPNCalc
extends java.lang.Object


Constructor Summary
RPNCalc()
          Constructs a new RPN calculator ojbect.
 
Method Summary
 void add()
          Pops two numbers off of the RPN calculator's stack; Adds the two numbers together, and places the result on the stack.
 void divide()
          Pops two numbers off of the RPN calculator's stack; Divides the second number popped off of the stack by the first, and places the result on the stack.
 void multiply()
          Pops tow numbers off of the RPN calculator's stack; Multiplies the two numbers and places the result on the stack.
 void number(float item)
          Places the given number on the calculator's stack
 void subtract()
          Pops two numbers off of the RPN calculator's stack; Subtracts the first number popped off of the stack from the second, and places the result on the stack.
 float top()
          Returns the top item on the RPN calculator's stack, does not remove the number from the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RPNCalc

public RPNCalc()
Constructs a new RPN calculator ojbect.
Method Detail

add

public void add()
Pops two numbers off of the RPN calculator's stack; Adds the two numbers together, and places the result on the stack. Prints an error message if there are not enough elements on the stack to perform the operation.

divide

public void divide()
Pops two numbers off of the RPN calculator's stack; Divides the second number popped off of the stack by the first, and places the result on the stack. Prints an error message if there are not enough elements on the stack to perform the operation.

multiply

public void multiply()
Pops tow numbers off of the RPN calculator's stack; Multiplies the two numbers and places the result on the stack. Prints an error message if there are not enough elements on the stack to perform the operation.

subtract

public void subtract()
Pops two numbers off of the RPN calculator's stack; Subtracts the first number popped off of the stack from the second, and places the result on the stack. Prints an error message if there are not enough elements on the stack to perform the operation

number

public void number(float item)
Places the given number on the calculator's stack
Parameters:
item - The number to be added to the stack.

top

public float top()
Returns the top item on the RPN calculator's stack, does not remove the number from the stack. Prints an error message and returns 0 if the stack is empty.
Returns:
The top number on the RPN calculator's stack, or 0 if the stack is empty.