Implement a console-interactive, stack-oriented calculator for stochastic variables in Java. Standard commands the calculator must deal with include
load <filename> | load the definition file (see below) |
list | list the names of all loaded types and operators with arguments identified |
help <name> | print help text for the indicated type, operator, or command |
<varname> <real>* | push a new stochastic variable of the named type with the given arguments |
<opname> | push an operator of the given name on the stack (consumes the appropriate number of elements from the top of the stack to build an in-memory expression tree becoming the new top-of-stack) |
amean | compute the analytical mean of the distribution at the top of the stack |
samples <k> | set the number of samples used for subsequent operations to be <k> |
hist | print a 20-row by 40-column histogram (using '*' characters) of the distribution at the top of the stack (using the number of samples set earlier) |
mean | print the sample mean (using the number of samples set earlier) of the distribution at the top of the stack |
sdev | print the sample standard deviation (using the number of samples set earlier) of the distribution at the top of the stack |
The definition file contains the names of Java classes, one per line, that should be loaded into the running program at the time the command is issued. These classes define all the variable types and operations available in the calculator. There should be no "built-in" distribution or operator. Implement at a minimum the following dynamically-loaded classes:
D <mean> | A "Deterministic" distribution with the given mean (a constant) |
U <low> <high> | A Uniform distribution between low and high |
N <mean> <sdev> | A Normal distribution with the given mean and standard distribution |
+ | Add the next two items on the stack |
- | Subtract the next two items on the stack |
* | Multiply the next two items on the stack |
/ | Divide the next two items on the stack |
neg | Negate the item on the top of the stack |
sum | Sum the remaining items on the stack |
prod | Multiply the remaining items on the stack |
Your design should make it easy and convenient for end-users to supply these sorts of classes, so provide appropriate convenience classes. Hand-in: