Home / Expert Answers / Computer Science / java-assignment-postfix-expression-calculator-nbsp-i-the-input-all-expressions-are-stored-pa569

(Solved): Java Assignment: Postfix Expression Calculator   I. The Input All expressions are stored ...



Java Assignment:
Postfix Expression Calculator

 

I. The Input

    All expressions are stored in a file called "in.dat". The file 
contains a sequence of arithmetic expressions in the postfix form, 
one per line. For example, the following file has two expressions:

    2 3 ^ 35 5 / -
    1 2 + 3 * # 4 - 5 6 - + _

There is at least one space to separate the operators and operands.
All operands and values are considered as doubles. 

    The following are the operators:

    +, -, *, /    arithmetic operators
    _             unary negation
    #             square root
    ^             exponentiation (a b ^ = a raised to the power b)

    There is a carriage-return at the end of the last expression.

II. The Output

    For each expression, your program should print the expression,
calculate its value, and show the result.

III. An example

    [lik@wyvern PostfixExpression]$ java PostfixExpression

    Hello! This is a postfix expression calculator.

    The value of "2 3 ^ 35 5 / -" is 1.0

    The value of "1 2 + 3 * # 4 - 5 6 - + _" is 2.0

    Bye-bye!

    [lik@wyvern PostfixExpression]$

IV. Testing

    You need to make a testing data file which contains all kinds of 
expressions to test your program thoroughly. It is a good exercise to 
design a nice input file.


We have an Answer from Expert

View Expert Answer

Expert Answer


Java COde:- import java.util.Scanner; import java.lang.Double; import java.io.File; import java.io.FileNotFoundException; import java.util.Stack; class PostFixExpression { static boolean divisionByZero = false; static boolean invalidChar = false
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe