Question: Write a program in java for rpn equation(stacks and queue). In this program you must create stacks without importing stacks . The program will prompt

Write a program in java for rpn equation(stacks and queue). In this program you must create stacks without importing stacks. The program will prompt the user to type in math fomulas and display the aswer on the screen.

Write a program in java for rpn equation(stacks and queue). In this

Answer 14

You are to write a program that allows the user to type in a mathematical formula at the keyboard and produces the answer on the screen. The formula will be typed in INFIX notation and will include only positive integers for the numbers. The operators that are acceptable are the following: (plus), minus (multiply (divide), an ower Parenthesis are also allowed. You should allow the user to type in the equation of his choice and then display the answer on the screen. Display a real answer. (for example: 3 /2 1.5, NOT 1) ALSO DISPLAY THE POST-FIXEQUATION ON THE SCREEN. The normal rules of mathematics apply parenthesis have the highest precedence followed by the A, followed by and followed by and +0 Do not allow the program to bomb and warn the user if the equation is wrong. For example: 2 +43 12 cannot be calculated because there are too many operators. When I test the program, I will only type positive integers as input and you can assume the input equation is valid Hints: You should treat the equation as a queue of tokens and read the tokens from the queue one at a time. Convert the INFIX equation to a POSTFIX equation. Then resolve the POSTFIX equation. Sample equations: Postfix 12 (2 4 /5 43 3 4 2 34 9 43 3 4 2 34 9 2 4 34 3 2 4 A 34 3 Here are 2 String methods that will come in handy: replaceAll and split Example of program running: Enter an equation 12 (6 4 (1+1) 2 RPN: 12 6 4 1 1 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!