Question: Prefix Expression Evaluation 3 . 1 . Problem Description Mathematical expressions usually use infix notation in which the operator is in between the operands: (
Prefix Expression Evaluation
Problem Description
Mathematical expressions usually use infix notation in which the operator is in between the operands: With prefix notation, the operator comes first:
You are to write a program that evaluates expressions written in prefix notation. The values will be all integers and the only operators you need to handle are and all of which retain their traditional meanings.
Note that with prefix notation, we are not limited to just two operands. That is we can add any number of values: evaluates to This also works for and is interpreted as and evaluates to
Here is the recursive definition of your expressions:
expression: integervalue
or: operator valuelist
valuelist : expression
or: expression valuelist
Operator: or or or
Notes
Your program can assume that the input is wellformed. For example, there will be no bad operators, floating point values, unmatched parentheses, or missing arguments. All the tokens in the input will be separated by whitespace space tab, or newline which means that you can use Scanner.getNext to get each token.
Your program is to continue to accept expressions until the user enters done Ignore case on this comparison.
Your output must include your name.
Your solution must be recursive.
Turn in only your source file: PrefixEvaluation.java.
Make sure your class is not in a package that is it is in the default package
Hint: Consider writing a single recursive method int evalString e which evaluates e If e is an integer the base case just return its value. If e isnt an integer, it must be start with a recursive case Read the operator next, then read, evaluate and store ArrayList expressions until you find the matching Once you have your values the operands to the operation perform the required operation and return its result.
Required Main Class
PrefixEvaluation
Required Input
A series of prefix expressions followed by done
Page
Required Output
For each expression, evaluate the expression and print the result. You can use the examples below as a set of test cases. Your output should look like the following input is in GREEN
Prefix Evaluation Your Name
Enter an expression:
Evaluates to
Enter an expression:
Evaluates to
Enter an expression:
Evaluates to
Enter an expression:
Evaluates to
Enter an expression:
Evaluates to
Enter an expression:
Evaluates to
Enter an expression:
Evaluates to
Enter an expression: DoneI need help
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
