Question: Writing a command-line Java program that evaluates NORMAL Polish notation (NPN) formulas. Here are the details: When run from the command line your program must

Writing a command-line Java program that evaluates NORMAL Polish notation (NPN) formulas. Here are the details:

  • When run from the command line your program must read from standard input an NPN

    formula.

  • You can assume there is a space between every operator and number. Every number will be

    a 32-bit integer.

  • Your program should be able to correctly handle the operations: +, -, x.

    IMPORTANT: be careful that your program recognises precisely the three characters above (plus sign, minus sign, and the lowercase letter x, respectively).

  • Your program then should write to standard out a single line with the correct output in a standard integer format. The following example shows the correct behaviour for your program:

echo + 75 125 | java test 200

Other examples of NPN formulas are:

  • 3( result is 3)

  • x 2 0 (result is 0)

  • x + 2 3 + 2 2 (result is 20)

  • + x 2 3 4 (result is 10)

IMPORTANT

  • As with all other assignments you may NOT use any Java standard library class or method other than for input/output.

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!