Question: You are to design and implement and algorithm in Java, to input an Infix expression , convert to a postfix expression and finally evaluate the

You are to design and implement and algorithm in Java, to input an Infix expression , convert to a postfix expression and finally evaluate the postfix expression Follow the examples done during class lectures

Problem description:

We are used to infix notation - 3 + 4 - where the operator is between the operands. There is also prefix notation, where the operand comes before the operands. A Reverse Polish Notation calculator uses postfix notation, and was one of the first handheld calculators built. At first, it seems confusing, but is very logical once you think about it. Instead of doing 2 + 3 + 4, you may do 2 [enter] 3 [enter] 4 [enter] + +.

You will be implementing a conversion from infix to RPN and then perform an RPN calculator for this assignment.

How does an RPN calculator work? It is quite simple in principle. The calculator keeps a stack - a list of numbers. When you type a number and hit enter, it pushes, or appends the number to the stack. So you build up a stack of numbers. Whenever you click an operand, it applies the operator to the top of the stack. In the previous example, it builds a stack like [2, 3, 4]. When you hit the first +, it pops off the top/most recent two elements off the list and pluses them. Lastly, it pushes the result back on the stack, so it looks like [2, 7]. When you hit plus again, it pops off the two elements (so the stack is temporarily empty), adds them, and pushes it back on the stack, so you get [9] .

3 What you need to do

For the first part of this assignment, think about what classes you need. Java has a Stack class for you, but write your own ( do nt use the Java Stack class). Use encapsulation, think about what methods it should have, and call it something like CalculatorStack. Add an option to roll the stack; shift it left or right by one (and the end number rollls) to the other end). Other classes may include Controller, Handler, or SpecialOperationsHandler.

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!