Question
(without using java stack library HAVE TO MAKE OWN STACK)You are to write a Java program that allows the user to type in a mathematical
(without using java stack library HAVE TO MAKE OWN STACK)You are to write a Java program that allows the user to type in a mathematical formula at the keyboard and produces the answer on the screen WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).WITHOUT USING JAVA STACK***** ( HAVE TO MAKE OWN STACK).
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), and ^ (power). 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-FIX EQUATION ON THE SCREEN.
The normal rules of mathematics apply (parenthesis have the highest precedence followed by the ^, followed by * and /, followed by - and +).
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 ->12 2 4 5 / +
43 + 3^4 * 2 / 34 9 ->43 3 4 ^ 2 * 34 / + 9 -
2 ^ 4+34 - 3 ->2 4 ^ 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 / +
Answer: 14
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started