Assignment 3
The Assignment
http://learnu.ics.hawaii.edu/~nickles/211_Spring_2005/labs/
stack_recursion/CalculatorApplet.html
Submission
- Email your assignment to ztomasze@hawaii.edu.
- Attach the source code of your Java application. Send me only the source code (.java files); do not include the .class or any other files. Do not zip or otherwise bundle the .java files.
- Send me at least MyCalculator.java and MyStack.java and any files
need to make these run (such as any node classes). You do not need to
submit the other files given to you.
- Also send me a link to a working version of your applet online.
Recommendations
Your MyStack needs to use a reference-based/dynamic implementation. (No arrays or other ADTs.) This means you will need to write some sort of node class. Here is a brief grader for your stack: StackGrader.java
Do not change any of the files given to you (except MyCalculator.java, which you need to fill in).
Your MyCalculator needs to handle numbers of multiple digits (that is, integers > 9). Do not need to handle decimal points or negative numbers. You should accept (but ignore) spaces for infixToPostfix . You will need to accept spaces in evaluatePostfix between consecutive operands (numbers). You may require a space between every operand and/or operator if you feel it necessary.
Think about how to handle errors from bad input: letters or other characters, missing operators, too many operators, mis-matched parentheses, etc. Throwing an exception will lock the applet. (That is bad.) Since we are not to change the applet code, what do you think would be the best thing to do in the case of an error or bad input?
There will be no grader for your calculator. This is chance for you to test your own code. Check that each operator works correctly, and that compound expressions (with more than one operator) work. Remember that a single operand with no operator (i.e., "5") is valid as both an infix and a postfix expression. Check that your calculator doesn't crash when given the invalid inputs described above.
As always, document the classes and methods that you write. Stack.java does not include JavaDoc comments, and so you will not inherit the documentation when you implement the interface this time. You will need to document MyStack ; you may use the comments in Stack.java to do this. If your evaluatePostfix or infixToPostfix input strings require special formatting, document what it is. If you create an auxilery method, document what sort of objects need to be in the stack, etc.
Grading:
Out of 10 points:
- 1 - Compiles
- 0.5 - Link to working applet.
- Send me a fully-qualified link: http://www2....
- 2 - Documentation and coding standards
- You will need to document all classes, methods, and constructors that you write for this assignment.
- 1.5 - MyStack
- Your stack must use a reference-based/dynamic/linked-list implementation. It needs to implement the given Stack interface code and work correctly.
- 2.5 -
infixToPostfix
- Needs to handle positive numbers of more than one digit.
- 2.5 -
evaluatePostfix
- Must use a recursive solution. (You will may create a recursive helper method to do this.)
Solution
Zach's Solution (zip file). Includes all the given interfaces, the given applet code, and a couple graders. MyCalculator has some hairy code, but it is quite flexible on the input it will accept and catches most (all?) illegal expressions.
|