Assignment 4
Due date: Thursday, Octomber 31, in the lab.
NOTES:
- 10% penalty for each day late, up to three days
- This is an individual assignment; no groups allowed
This assignment requires JAVA object oriented techniques. You will practice the Stack data structure.
Problem description
Write a program EQ-Calculator according to the following requirements:
Requirements:
- The input of EQ-Calculator is an arithmetic expression in the infix notation. The aritmetic expression can have paranthesis, such as (), {} and [].
- The aritmetic expression may contain variables. If variables are present EQ-Calculator must identify them and prompt the user to input values.
- EQ-Calculator must first check that the expression has balanced paranthesis regardless of the presence of variables in the expression. If the expression is not balanced then your program must output and error message and prompt the user to input another expression.
- If the expression is correct, then EQ-CalculatorĀ must convert the original expression into the postfix notation (hint: no paranthesis are present in the postfix notation). Diplay your expression in the postfix notation.
- Evaluate the expression using its postfix representation. Display each step of the evaluation algorithm. If there are any errors (stack overflow or underflow, or a bad token), simply output "error" to the standard output.
- EQ-Calculator must support the four basic operators +, -, *, and /.
- In the input, you may assume that all tokens are separated by spaces.
Bonus points
- (1 points). If the brackets do NOT match, report the character number where it discovered the error (starting at 0 from the left) and the incorrect character it
found there. For example, for the input string:
2{3(x]5}y
the output from the program should be:
Error: ‘]’ at position 5
- (1 points): Allow your expression to include unary operators, such as ++ and --
.
Bonus Points: Develop a user interface for the project.