Write a Java program that converts a given infix expression (input) to the corre
ID: 663830 • Letter: W
Question
Write a Java program that converts a given infix expression (input) to the corresponding postfix expression (output) and then evaluates the postfix expression to return the answer (output).
Programming: You must use stack to convert to postfix expression and then evaluate it. You may use your own stack class that you might have already created
The main() method is responsible to capture the input (infix expression), scan it, check for its correctness, and produce output.
Sample input:(4 * (2 + 3)) / (8 * 5) Corresponding Output: Postfix expression: 4 2 3 + * 8 5 * / Evaluated value: 0.5
For any input, program must display two outputs: (i) the postfix expression, and (ii) the evaluated value.
Program should not suffer from runtime errors. All exceptions should be handled properly. Especially, if the user has entered an infix expression with wrong number and/or nesting of parentheses your program should show an error message (you may use a stack for this check). You can assume that there will not be any { or [ used in the expression and only +, -, *, / are used as operations.
Explanation / Answer
//function for evaluating expression value
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.