gorithm (logic) to process reverse polish notat he operators +, -, and * are will always returni perators should also return integer expression nplement the ^ operator. However, be awaret

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please code the following and pleace us Stack<T> 

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

Given

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: 43 -5 6 + 4 * -Result: -43 
Line: 1 1 + 3 * 4 - 10 A Result: 1024 

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY