Expert answer: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 expressionplease see the attachment for more info about the assignment
csc241programming_2.docx
Unformatted Attachment Preview
Programming Assignment 2 – RPN Calculator –
Infix to Postfix Conversion and The Evaluations of the Postfix Expression.
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:
1. 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] +
+”.
2. You will be implementing a conversion from infix to RPN and then perform an RPN
calculator for this assignment.
3. 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.
4 Why?
• It’s one of the better assignments I can think of as a teaching tool
• RPN calculators are awesome – they’re far more logical than infix calculators once
you get used to them
• You should learn RPN calculators; besides the historical importance, it forces you to
think differently. Several example done during class lectures.
The following code below is a sample on how to evaluate the RPN expression …
…
Purchase answer to see full
attachment
You will get a plagiarism-free paper and you can get an originality report upon request.
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more