P7: Decorator HP Calculator

Due Monday, November 4th, 12noon

In this assignment, you will write a command-line version of an HP calculator that uses decorators as the main instrument for implementing calculator computations.  In effect, you will enter a sequence of commands via the command line, and the output will be the result:

> java hp35.Main  4 3 2 x + 
4 3 2 x + = 10
>

The goals of this assignment are for you to learn:

Again, if there is any question about what is the correct answer to a sequence of questions, consult the HP 35 emulator of P6.

Below I show a class diagram for a set of decorators of the End action (which does nothing) -- it is the terminal (base) of all decorator chains.  All the computations that can be performed are accomplished by decorators:


The following command-line arguments:
> java hp35.Main 4 3 2 x +
will produce the following decorator chain -- one decorator for each command line argument, with the base (terminal) of the chain is an instance of End:



Creating this chain is, frankly, very easy.  Once you have the chain (whose head is pointed to by variable Chain), you simply execute the lines:
stack = new Stack<float>();
Chain.print(stack);
Chain.compute(stack);
System.out.println(" = " + stack.pop());
if (!stack.isEmpty())
System.out.println("stack not empty -- missing arguments");

Your task is to:

What You Are To Submit

You are to submit a working Calculator that parses and correctly evaluates the following script.  You can invoke this script  by typing:

> java hp35.Main -f testscript.txt

Your program may be subjected to other scripts when being graded.  Specifically:

A critical part of any design is clarity and understandability.   Hence, you will be graded on the clarity of your project and its ability to work correctly.  Sloppy code, documentation, or anything that makes grading or understanding your program difficult will cost you points!  Beware, some of these "beauty" points are subjective. 

No late assignments/submissions will be accepted.