subject

Introduction For this project, you will implement an RPN calculator that reads a series of expressions in RPN form from a file. The user has two options: they can either enter the filename as a command line argument or they may be prompted for a filename after launching the program. In either case, the program halts if the file does not exist.

Individual expressions in RPN format (see below) are read from the file. If an expression is well-formed the program will evaluate it and display the expression along with its results on the console. Malformed expressions result in an error message being displayed on the console.

Overview

Infix notation is the notation commonly used in arithmetical and logical formulae and statements. It is characterized by the placement of operators between operands—"infixed operators"—such as the plus sign in 2 + 2. Infix notation is more difficult to parse by computers than prefix notation (e. g. + 2 2) or postfix notation (e. g. 2 2 +). However many programming languages use it due to its familiarity.

In infix notation, unlike in prefix or postfix notations, parentheses surrounding groups of operands and operators are necessary to indicate the intended order in which operations are to be performed. In the absence of parentheses, certain precedence rules determine the order of operations.

Reverse Polish Notation (RPN), also known as postfix notation, is a mathematical notation in which operators follow their operands, in contrast to Polish Notation (PN), in which operators precede their operands. Expressions in this form do not require any parentheses as long as each operator has a fixed number of operands.

In postfix notation, the operators follow their operands. For example, to add 3 and 4, you would write 3 4 + rather than 3 + 4. If there are multiple operations, operators are provided immediately after their second operands. The expression written 3 − 4 + 5 in conventional notation would be written 3 4 − 5 + in RPN: 4 is first subtracted from 3, then 5 is added to it. A distinct advantage of RPN is that it removes the need for parentheses that are required by infix notation.

RPN Algorithm

for each token in the postfix expression:

if token is an operator:

operand_2 ← pop from the stack

operand_1 ← pop from the stack

result ← evaluate token with operand_1 and operand_2

push result back onto the stack

else if token is an operand:

push token onto the stack

end_for

result ← pop from the stack

Program Requirements

Design a program with the following specifications:

Required Program Name: RPN. java
The program can use either command line arguments or standard input (the CLI) to enter in a file name. For standard input, the program should use standard output to prompt the user for the name of a file. This file contains a set of expressions in RPN format.
If the input file does not exist or an I/O error occurs while processing it, an error message is displayed and execution halts.
The input data file is a plain ASCII text file containing RPN expressions of varying length and complexity.
Each expression is evaluated and any malformed expressions generate an error message.
Program output should be neat and adequately spaced for readability.
Program Implementation

Using a Stack ADT, implement the program as a Java application within a single compilation unit.
Using only integer values, implement the following operators: addition (+), subtraction (-), multiplication (*), integer division(/) and positive number exponentiation (^).
For internal documentation, use plenty of comments throughout the program.
Be sure to include your name and course/section in the application documentation block.
For grading, submit a copy of the source code and a screen snapshot of the program execution.

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:00, starwarsfan1975
Meenu wants to create a high quality drawing in a variety of colours. which device should she use for the same?
Answers: 1
image
Computers and Technology, 23.06.2019 02:30, jaueuxsn
Which component acts as a platform on which application software runs
Answers: 2
image
Computers and Technology, 23.06.2019 11:30, magicalpenguin48
In cell h5 enter a formula that will calculate the percentage of attendees that went to the altamonte springs job fair in 2018.
Answers: 1
image
Computers and Technology, 23.06.2019 15:10, cathyjuan
What role did women fill during world war ii?
Answers: 1
You know the right answer?
Introduction For this project, you will implement an RPN calculator that reads a series of expressi...

Questions in other subjects:

Konu
Mathematics, 05.05.2020 03:41
Konu
History, 05.05.2020 03:41