Question: Help? I need this in Dr Java ASAP Reverse Polish Calculator! Objective Write a program that will populate a queue with post-fix (reverse polish) integer
Reverse Polish Calculator! Objective Write a program that will populate a queue with post-fix (reverse polish) integer expressions and then print out the solution to you've seen in math is called in-fix notation each expression. To understand this mostly every expression In-fix Example: 3 2 However in post-fix notation the operator is at the end of the expression. Post-fix Example: 3 2+ A stack is used to calculate values in post-fix notation. Numbers are pushed onto the stack, and when an operator is reached it pop back on the stack. See these EXAMPLE SLIDES for further information. s off the last two numbers and then pushes the resulting value This program must .Assume that each number and operator is separated by any type of space, and each expression is separated by a new line Calculate values using the algorithm mentioned above and in the slides for addition, subtraction, multiplication, and division (+,-, Error message if the user tries to divide by zero . Read a given file Make sure to check if there's at least two items on the stack before when an operator is encountered or else it's not a properly formatted post-fix expression Finish when the program reaches the end of the string and it has only one value left on the stack, then that value is popped off and returned. Otherwise it was not properly formatted Use your own created stack and queue, and not java's built in stack and queue o You may use any implementation so either an array or a linked structure. HINTS! First when you're processing the inputted string you can use a Scanner and call the method next0 to get each token. From there you can evaluate if that token is an operator, numeric value, or an error. If it's a numeric value then you may parse that string using Integer.parselnt0 to get the integer value. You may also call Integer.parselnt0 in a try-catch block. If the token is not an integer an exception will be raised and should be immediately halted
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
