Must be done in Java. In the 1980s HP produced postfix calculators, which enabled people to perform...

80.2K

Verified Solution

Question

Programming

Must be done in Java.

In the 1980s HP produced postfix calculators, which enabledpeople to perform arithmetic calculations without usingparentheses. The problem was that we had to first learn how toconvert a \"normal\" arithmetic expression (known as an infixexpression) to postfix before we could use the calculator.

Then the calculator uses a stack to evaluate the expression .The following tutorial shows you how to use a stack to calculatethe result of a postfix expression (and then it has a review of howto convert from infix to postfix. (You need to be able to do thisfor a test).

This program will use a stack to evaluate postfix expressions.The input file will consist of several postfix expressions, one perline. (I suggest you practice with input from the keyboardinitially while you debug your program). In the input file, theoperands will be single digit integers. Output the expression andthe evaluation. For example, if the input was 23+ you should output\"23+ is 5\".

Note: You may assume the only things in the input string aredigits and operators +,-,*,/

As always, document your program. I expect to see the algorithmwritten in the comments.

Make sure you put the input file in the correct place in theproject, zip the folder and submit it.

I am adding 5 points extra credit to this assignment (that is25% extra)

To get this extra credit you need to have a method to get theinput, one to perform the calculation, and one to output. Put yourpostfix calculation in a method called postfix. This method willaccept a string as parameter (the input string) and return aninteger. (either a primitive int or an Integer, your choice).

Rubric:

Comment to state what the program does

Comments within the body of the program

use of try/catch with input file

Correctly declare, initialize, and use a stack

Correct calculation

This criterion is linked to a Learning OutcomeNicely formedoutput

EXTRA CREDIT. 3 methods (input, postfix, output)

Answer & Explanation Solved by verified expert
3.6 Ratings (393 Votes)
Based onabove Questioncode Written below The code shown below is a Infix to Postfix converterpackage comcompany Replace with your own package and uncommentthe lineimport javaioBufferedReaderimport javaioIOExceptionimport javaioInputStreamReaderimport javautilScannerimport javautilStackpublic class InfixToPostFixConverter Value holding stackprivate Stack1 operandHoldingStack The Character sequence to be extractedprivate String input The Character sequence to be returnedprivate String output private int result 0 Construct the InfixPostfixStack object param inPutChars input string to be convertedpublic InfixToPostFixConverterString inPutChars input inPutCharsint stackSize inputlengthoperandHoldingStack new Stack1stackSize Converts infix to postFix return postfixed stringpublic String transferToPostFix The subroutine to    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students