Starting from:
$30

$24

Homework # 10 Solution

You will develop a Java program that will take arithmetic expressions from the user and will evaluate them. For example, the following will be a sample run for your program




Enter your expression, after each operator or operand press enter, to end the expression press = Enter your expression element

3

Enter your expression element

+

Enter your expression element

7

Enter your expression element

*

Enter your expression element

(

Enter your expression element

1

Enter your expression element

+

Enter your expression element

2

Enter your expression element

)

Enter your expression element




=




Results is

30




Your program will have at least the following classes:

class Operator that can keep the operators such as *,+,-,/
class Operand that can keep the integer operands only
class Paranthesis that can keep ( and )
class Expression that

keeps an array of expression elements
evaluates the array of expresion elements
has a working toString and equals methods.



The algorithm for the evaluation for expression can be as follows




From the array of expression elements, find the highest priority operator, perform the operation, out the results back into the array of expression. For example, for the expression

3 + 5 * 8 would be become 3 + 40 and then it becomes 43

For the paranthesis, find the inner most paranthesis pair first, evaluate the expression in it, and continiue with the rest of the expression.

Test your classes and the overall program with many inputs, including inputs with errors. Include JavaDoc files and test runs with your submission.

More products