Question: java Create an application that can evaluate an infixed expression by using the Generic Stack structure then print out the result in the following format:
java
Create an application that can evaluate an infixed expression by using the Generic Stack structure then print out the result in the following format:
For example
Read an infixed expression,
(1 + 2) * 4 3
The output should be: (1 + 2) * 4 3 = 9
The application should allow users to choose where to read the expression: from the keyboard or from a file (file stores one expression on one line)
After finishing one expression, the application should loop back to allow users to select the source to read the expression from then continue to do until the users want to exit
Add a class GenericStack that can apply for any data type. You can use the code of GenericStack in the book page 167 for your reference (You do not need GenericNode and deepCopy for this lab)

Add the driver class named InfixedExpression that has 5 user defined functions, one function of phase 1, one function for phase 2, one function of process One Operation, one function for procesOneExpression and one function for display output
User Defined function processOneOperation
This method accepts two paramenters, Integer Stack and Character Stack
In the body of the method 0neoperatorProcess
-pop the top operator in the stack of operators
-pop the two operands on the top of stack of operands
-Depend on the operator, calculate the result
-push the result back to the stack of operand.
User Defined function procesOneExpression that hold all the code to evaluate one expression
-After reading one expression as a string
-Using StringTokenizer or split of String to split input expression into the tokens (operands and operators) and store them to stack of operands and stact of operators by applying the following rules:
phase1: Scanning expression (read expression) the program will scan the expression from left to right to extract operands, operators and the parenthesis
if the extracted item is a number, push it to the stackForOperands
if the extracted item is a + * or / operator:
-check if the Stack for operators is empty, push it into the stack
-if the Stack for operator is not empty
* if extracted item is + or -, process all operators + - * / at top of the stack for operators then push it in
* if extracted item is * or /, process all operators * / at top of the stack for operators then push it in
if the extracted item is an open parenthesis (, push it to stack for operators
if the extracted item is an close parenthesis ), process all operators in the stack for operators from the top until top is an open parenthesis (; then pop the open parenthesis ( off from the stackForOperators phase2: Clearing stack
Process all the operators left in the stack for operators from top until stack for operators is empty
Display the result as the required format: The final result will be the last number in the stackForOpereands
1. public class GenericStack
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
