Program Output Line: 2 3 4 + + Result: 9 Line: 12 6 / 4 * 4 + Result: 12 Line: 2 2 3 3 * ** Result: 36 Line: 7 5 / 5 + 17 - Result: -11 Line: 4 3 - 5 6 + 4 * - Result: -43 Line: 1 1 + 3 * 4 - 10 ^ Result: 1024

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please use java code and create a program that completes the task below. 

In class we developed code for a Generic Stack. The classes were Node, StackArray, StackRefas well
as the Stack interface. All were generic and use the <T>type parameter. We also developed the
algorithm (logic) to process reverse polish notation (RPN) expressions, such as 23 + or 234 + * 2 *
The operators +, -, and * are will always returninteger values gives integer expressions. Your/and ^
operators should also return integer expressions. You are likely to use the Math.pow method to
implement the ^ operator. However, be aware that it returns a result of type double.
Use the Stack interface and the Node and StackRef classes in a new project called RPN. You will add
a client program to readthe data file below which achieves the out put as specified below. You will need
to determine a stack parameter <T> to use. Since you are reading a file (line by line), you will read each
line as a String. You will need to break up that line into a series of tokens. The String split method is
an easy way to create an array of Stringtokens. For example, after reading the line "12 6/4 * 4 +"
split will produce an array of 7 String elements (7 tokens). For each token you will need to determine
if it is an operator or an operand, and act according to your RPN processing algorithm. To determine if
the token is an operand, you may want to create a Set<String>ofall possible operators, then use the
contains method to determine if the token is an operator. If you determine that the token is an operand
(integer), you will want to push it on the stack. Since the token is always a String, you can push the
operand as a String (on your Stack<String>) or convert it to an integer value using the
Integer.parseInt() method and push the operand as an int (on your Stack<Integer>). Whichever
Stack parameter<T> you use, you will need to convert the String-stored integer value to an int-
before pushing or after popping it off.
Create a project and demonstrate that you can process a file of RPN expressions. All lines in this sample
Data File are correct. You do not have to tryto catch bad input in this lab.
Data File
234 ++
12 6/4 * 4 +
2233 ***
75/5+ 17 -
43 -5 6+4 * -
11+3 * 4 - 10 ^
Transcribed Image Text:In class we developed code for a Generic Stack. The classes were Node, StackArray, StackRefas well as the Stack interface. All were generic and use the <T>type parameter. We also developed the algorithm (logic) to process reverse polish notation (RPN) expressions, such as 23 + or 234 + * 2 * The operators +, -, and * are will always returninteger values gives integer expressions. Your/and ^ operators should also return integer expressions. You are likely to use the Math.pow method to implement the ^ operator. However, be aware that it returns a result of type double. Use the Stack interface and the Node and StackRef classes in a new project called RPN. You will add a client program to readthe data file below which achieves the out put as specified below. You will need to determine a stack parameter <T> to use. Since you are reading a file (line by line), you will read each line as a String. You will need to break up that line into a series of tokens. The String split method is an easy way to create an array of Stringtokens. For example, after reading the line "12 6/4 * 4 +" split will produce an array of 7 String elements (7 tokens). For each token you will need to determine if it is an operator or an operand, and act according to your RPN processing algorithm. To determine if the token is an operand, you may want to create a Set<String>ofall possible operators, then use the contains method to determine if the token is an operator. If you determine that the token is an operand (integer), you will want to push it on the stack. Since the token is always a String, you can push the operand as a String (on your Stack<String>) or convert it to an integer value using the Integer.parseInt() method and push the operand as an int (on your Stack<Integer>). Whichever Stack parameter<T> you use, you will need to convert the String-stored integer value to an int- before pushing or after popping it off. Create a project and demonstrate that you can process a file of RPN expressions. All lines in this sample Data File are correct. You do not have to tryto catch bad input in this lab. Data File 234 ++ 12 6/4 * 4 + 2233 *** 75/5+ 17 - 43 -5 6+4 * - 11+3 * 4 - 10 ^
Program Output
Line: 2 3 4 + +
Result: 9
Line: 12 6 / 4 * 4 +
Result: 12
Line: 2 2 3 3
Result: 36
Line: 7 5 / 5 + 17 -
Result: -11
Line: 4 3
Result: -43
5 6 + 4 * -
Line: 1 1 + 3 * 4 - 10 ^
Result: 1024
Transcribed Image Text:Program Output Line: 2 3 4 + + Result: 9 Line: 12 6 / 4 * 4 + Result: 12 Line: 2 2 3 3 Result: 36 Line: 7 5 / 5 + 17 - Result: -11 Line: 4 3 Result: -43 5 6 + 4 * - Line: 1 1 + 3 * 4 - 10 ^ Result: 1024
Expert Solution
Step 1

To write java code for evaluating the given expression.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education