Due: July 19th 5:30pm


Create a simple RPN Calculator in Java, such that:

The main class is called Calculator.

An interface exists called StackElement.  The interface has a method called getInfo() which returns the string "I am an Operator" in the case of Operator instances, and "I am an Operand" in the case of Operand instances.

A java.util.Stack object exists that is called TheStack, which is a LIFO queue.  TheStack holds StackElement objects.

There are two concrete implementations of a StackElement, they are:  Operator and Operand

The Operator class is an abstract base class, and defines an operation (method) called execute().

Both Operator and Operand objects may be put on and taken off the stack

There are four types of Operator subclasses:  Add, Subtract, Multiply, and Divide

There are four types of Operand subclasses:  RPNInteger, RPNLong, RPNFloat, and RPNDouble.  Each of these compose a java.lang.Integer, java.lang.Long, java.lang.Float, or java.lang.Double object, respectively.

The Operand class has a method called getValue(), which returns the appropriately composed inner value, ie., an Integer, a Long, a Double, or a Float value.

The Operator class has an abstract method on it called execute().  The execute() method will execute the current stack, which should end with an instance of an Operator class. 

The Operator, when executed, will walk the stack, pulling off instances of the Operand class, and performing the calculation, until the end of the stack is reached.

The Operator.execute() method is abstract, and is polymorphically handled by each Operator subclass.  Thus, Add, Subtract, Multiply, and Divide all provide concrete implementations (overrides) of the abstract Operator.execute() method.

The Calculator class must exist in the following package:  edu.uchicago.cs.cspp51035. 

The Calculator object will prompt the user for a string of text.  The text entered will be valid (you MUST provide errorhandling in some fashion for invalid input) RPN text, such as "2 2 +" or something like that.  The Calculator will parse the input string, using a StringTokenizer object.  Each token will be analyzed to discover the appropriate wrapper class (Operator or Operand) to instantiate, and then wrapper class will be pushed onto TheStack.  Once the tokens have all been pushed, the Calculator will call the last object's execute() method to begin the execution of the stack.

Attention1: Please make sure you deal with the type correctly. For example, 3 / 4 = 0, while 3.0 / 4 = 0.75.

Attention2: Give yourself a self-test like 3+4*2/(1-5)-2;


Write the list with questions.