Menu

(Solved) : Part2 Requirement Evaluating Infixed Expression Create Project Named Fa2018lab4part2yourla Q31783762 . . .

PART2 Requirement Evaluatingthe inFixed Expression

Create a project named FA2018_LAB4PART2_yourLastName
Add a data structure named GenericStack
Provide the application that allows users to evaluate the infixedexpressions. First, allow users to select where the expressioncomes from:

One Expression from the keyboard

Expressions from an input filee

Case 1: //input from the keyboard

-After reading one expression as a string
-Using StringTokenizer or split of String to split input expressioninto the tokens (operands and operators) and store them to stack ofoperands and stact of operators by applying the followingrules:

phase1: Scanning expression (read expression)
the program will scan the expression from left to right to extractoperands, operators and the parenthesis

 if the extracted item is a number, push it to thestackForOperands

 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 + – * / attop of the stack for operators then push it in
* if extracted item is * or /, process all operators * / at top ofthe stack for operators then push it in

 if the extracted item is an open parenthesis (, push it tostack for operators

 if the extracted item is an close parenthesis ), process alloperators in the stack for operators from the top until top is anopen parenthesis (; then pop the open parenthesis ( off from thestackForOperators

PHASE 2: Clearing stack
 Process all the operators left in the stack for operators fromtop until stack

for operators is empty

DISPLAY THE RESULT as the required format: The final result willbe the last number in the stackForOpereands

Case 2: input from a file Read file name
Open file
Loop to read file

Read each line as one String that is an expression DO THE PHASE1
DO THE PHASE 2
DISPLAY THE RESULT

*Step1: Create the pseudo-code [QA2] *Step2: Write the code

-start editor create the project, add .java file [QA1b] or[QA1d]

-follow the pseudo-code and use java to write the code of theprogram *Step3: compile and run the program
*Step4: debug if there is any errors to complete the program

HINTS:

1. Create the project FA2018LAB4_PART2_yourLastName
2. Add a class GenericStack that can apply for any data type. Youcan use the

code of GenericStack in the book page 167 for your reference(You do not need GenericNode and deepCopy for thislab)

3.
Add the driver class named

FA2018LAB4_EvaluatingInfixedExpression_yourLastName that has5 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 displayoutput

User Defined function processOneOperation

This method accepts two paramenters, Integer Stack and CharacterStack 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 thathold all the code to evaluate one expression

Expert Answer


Answer to Part2 Requirement Evaluating Infixed Expression Create Project Named Fa2018lab4part2yourla Q31783762 . . .

OR