Implement the RPN calculator pseudo-code supplied in the lecture as real code.
Your program must:
1.Prompt the user for an infix math problem.
2.Convert the problem to postfix.
3.Output the problem in postfix.
4.Calculate the result.
5.Display the result.
6.Ask the user for another math problem.If the user entersquitfor the problem, end the program.
Use the standardstack and queue class/methodology provided by your preferred language's framework, such as the STL stack/queue classes in C++ or the Array class in JavaScript. Put the conversionprocedure in its own function. Put the calculate result procedure in its own function as well.You need to handle multi-digit numbers even though the sample code does not. In your version, numbers (operands) are separated from operators by zero or more spaces, while numbers are separated from other numbers byoneor more spaces. While negative numbers cannot be input by the user, the result may be negativebased on the input math problem.You must support +, -, *, /, and % operators, as well as (potentially nested) parenthesis. For +10 extra credit, also support raising a number to a power with the POW operator, which must appear as those three letters in all uppercase.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class InfixEvaluator

    public double evaluatePostfix(Queue<String> postQ){

       Stack<Double> eval = new Stack<>();
       // postQ contains the postfix expression to be evaluated.
       try {
            String t;
            double topNum, nextNum, answer = 0.0;
            while (!postQ.isEmpty()) {
                t = postQ.poll();
                boolean isNumber = true;
                double num = 0.0;
                try {
                   num = Double.parseDouble(t);
                } catch (NumberFormatException ex) {
                   isNumber = false;
                if (isNumber) {
                } else {
                   topNum = eval.pop(); // Get operand from stack
                   nextNum = eval.pop();
                   switch (t) {
                        case "+":
                            answer = nextNum + topNum;
                        case "-":
                            answer = nextNum - topNum;
                        case "*":
                            answer = nextNum * topNum;
                        case "/":
                            answer = nextNum / topNum;
                        case "%"...

By purchasing this solution you'll be able to access the following files:
Solution.png and

50% discount

$25.00 $12.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats