Homework 6

Due: Wednesday 3/23/2005 by 12:00 p.m.

- As private members of the class, an array of Objects (the arithmetic expression is stored as a sequence of integers and operators) and its length. Your expressions will be built up from atoms which are "numbers" and the arithmetic operators +, -, * and /
- A constructor, initializing the expression to be empty (i.e. its length is 0).
- A member function for initializing the array by reading the expression from (a single line of) the standard input.
- A member function for printing the expression to the standard output.
- A member function for evaluating the arithmetic expression, using the
algorithm described in class. This
**should**make use of one of the Stack classes that you created and/or tested in Hw 5.

Careful: the expression is a sequence of Objects, but the values you push onot the stack, some resulting from evaluating a subexpression of an arithmetic expression, are integers. - Design a test driver for your class, as a Java application. Test your program on a few arithmetic expressions with at least 5 operators.
- Test tour program on all the expressions given in the following data file. Notice that each arithmetic expression occupies at most one line. Make the assumption that this is indeed the case, when you design the method reading an expression from the standard input.

The GUI should have the look of a real calculator, with buttons for punching in digits and operators and a textfield where the expression is displayed. The user will type in an arithmetic expression in postfix form. When a button marked with the

Test your program on all the arithmetic expressions illustrated by the applet shown in class (look in the Java console).

- Develeop later the method for reading the expression from user input. You may start with some hardwired expressions, initialized in the constructor.
- Similarly for the applet: the complete user interface, with expressions read from a text field, should be left for the extra credit part.
- The user interface should be developed only after you have completed and tested part I. You may incorporate the features one by ine, starting with some empty actions (or simply printing on the Java console) for some buttons.
- Start by entering the expression via button clicks. The expression should then be displayed on the Java console and, eventually, in a text field.

- Extend the GUI with a text field for entering the expression. When the user presses return, the expression is evaluated.

Ileana Streinu