Back to 211 Main Page

Mobius strip

Assignment 4

The Assignment

http://learnu.ics.hawaii.edu/~nickles/211_support/labs/StackApplet.htm

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 all the files needed to run your program.
  • Include a fully-qualified URL to your working applet on the Web. (Include the http://... part.)

Recommendations

You should separate your stack, your postfix calculator, and your user interface into separate classes. Here is one way to break down this assignment into classes:

Node
Used by: MyStack
Alternate class name: DLLNode
You can reuse your DLLNode from Assignment 3. You don't even have to make your links two-way, but only connect the "next" links. (This is a bit of a hack, but it means you don't need to write any new code.)
MyStack
implements Stack
Uses: Node, java.util.EmptyStackException
Used by: PostfixCalculator
MyStack implements Stack.java from Nickles's website. Follow the code and not the documentation. That is, you don't need to implement the search method, but you should implement popAll. You can test your implementation with this StackGrader.java.
PostfixCalculator
Uses: MyStack
Used by: CalcButton
Alternate class name: PostfixCalc, etc
This class should have a method that converts an infix expression to postfix format, and a method that solves a postfix expression. Here are a couple sample method prototypes:
  • String convertToPostfix(String infix)
  • float solve(String postfixExpr)
You can call these methods whatever you like. Your convertToPostfix only needs to handle the four basic arithmetic operators (+, -, *, /) and parentheses. It should be able to handle integers of more than one digit. If you want to, you can also support spaces, decimal numbers, and negative numbers. I highly recommend you return a float (instead of doing "integer math").

I also recommend that you don't create your MyStack instance as a member/global variable. Instead, create a new stack as a local variable for each of your methods. That is because you're using a stack for a different purpose in each method, and you don't need the stack to exist between method calls.

Your methods can either throw a java.lang.IllegalArgumentException or an exception of your own making that extends java.lang.Exception if an invalid expression is passed to one of these method.
StackBox
extends java.awt.Frame
Uses: CalcButton, QuitButton
Used by: PostfixCalcApplet
Alternate class name: PostfixCalcFrame, PostfixCalcBox, etc.
This is the equivalent to Nickles's example TalkBox. Note that, after modularizing the user interface, it does not implement ActionListener. Instead, the buttons implement it and process their own ActionEvents.
CalcButton
extends java.awt.Button implements java.awt.ActionListener
Uses: PostfixCalc
Used by: StackBox
Alternate class name: CalculateButton, SolveButton, EvalutateButton, etc
Your constructor will probably need to take a reference to an input/infix text field and a output/result textfield.
QuitButton
extends java.awt.Button implements java.awt.ActionListener
Used by: StackBox
Alternate class name: CalculateButton, SolveButton, EvalutateButton, etc
Your constructor may need a reference to the enclosing/parent frame if you want to dispose() it.
PostfixCalcApplet
extends java.applet.Applet
Uses: StackBox
Alternate class name: StackBoxApplet, A4Applet, etc
This applet only needs a two-line init() method that creates a PostfixCalcFrame instance and sets it visible. You may also include a main() method as well.

If you want to get fancier, you can give this a proper applet interface of its own, with a button that will start your StackBox popup. You could also include instructions on how to use your calculator.

Grading:

Out of 10 points:

1.5 - Complete and valid submission.
Includes all the needed files. Compiles and runs. Includes a link to a working version of the applet on the web.
2 - Documentation and coding standards.
Since there are so many methods, I'm going to be rather lenient on documentation for this one. You don't need to use any of the @tags. If you can adequately describe each method in a single sentence, that's all you need. (Note that some of the methods, especially in the PostfixCalculator, probably have too much going on to be adequately documented in one sentence.)
2.5 - MyStack
It should implement the given Stack.java interface, and it should work correctly. It may not use java.util.Stack in its implementation. (You may use java.util.EmptyStackException if you want, though.)
2 - Converts from infix to postfix
I want to see the postfix form in the output of your applet.
1 - Solves the postfix form
Displays the correct result in your applet.
1 - Modularized applet
Your applet is modularized if your StackBox does not implement ActionListener, but instead each Button catches its own action and processes it accordingly.

Solution



~ztomasze Index : TA Details: ICS211: Assignment 4
http://www2.hawaii.edu/~ztomasze
Last Edited: 04 Nov 2004
©2004 by Z. Tomaszewski.