USE the Node, StackArray, StackRef and Stack interface classes PROVIDED BELOW to create code that reads input from the sample Data File PROVIDED to solve PLEASE READ DIRECTIONs VERY CAREFULLY thanks for your help Data File 2 3 4 + + 12 6 / 4 * 4 + 2 2 3 3 * * * 7 5 / 5 + 17 - 4 3 - 5 6 + 4 * - 1 1 + 3 * 4 - 10 ^ public class Node

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

USE the Node, StackArray, StackRef and Stack interface classes PROVIDED BELOW to create code that reads input from the sample Data File PROVIDED to solve

PLEASE READ DIRECTIONs VERY CAREFULLY

thanks for your help

Data File
2 3 4 + +
12 6 / 4 * 4 +
2 2 3 3 * * *
7 5 / 5 + 17 -
4 3 - 5 6 + 4 * -
1 1 + 3 * 4 - 10 ^

public class Node <T>
{

    private T data;
    private Node<T> next;
    
    public Node(T data, Node<T> next)
    {
        this.data = data;
        this.next = next;
    }
    
    public T getData()
    {
        return data;
    }
    
    public Node<T> getNext()
    {
        return next;
    }
    
}

 

import java.util.Stack;

public class StackArray<T> implements Stack<T> {
    private T [] elements;
    private int top;
    private int size;
    
    public StackArray (int size)
    {
        elements = (T[]) new Object[size];
        top = -1;
        this.size = size;
    }
    
    public boolean empty()
    {
        return top == -1;
    }
    
    public boolean full()
    {
        return top == size - 1;
    }
    
    public boolean push(T el)
    {
        if (full())
            return false;
        else
        {
            top++;
            elements[top] = el;
            return true;
        }
    }
    
    public T pop()
    {
        T el = elements[top];
        top--;
        return el; 
    }

}

 

// Generic Stack Reference Implementation

public class StackRef<T> implements Stack<T>
{

    private Node<T> top;
    
    public StackRef (int size)
    {
        top = null;
    }
    
    public StackRef()
    {
        top = null;
    }
    
    public boolean empty()
    {
        return top == null;
    }
    
    public boolean full()
    {
        return false;
    }
    
    public boolean push(T el)
    {
        Node<T> node = new Node<>(el, top);
        top = node;
        return true;
    }
    
    public T pop()
    {
        if (empty())
            return null;
        
        T el = top.getData();
        top = top.getNext();
        return el; 
    }
    
    
}

 

// Generic Stack Interface

public interface Stack<T>
{
    public boolean empty();
    public boolean full();
    public boolean push(T el);
    public T pop();
    
}

 

import java.util.Scanner;
import java.util.Stack;
import java.util.Set;
import java.io.*;
import java.util.*;

public class RPN {

    private static Stack<String> stack;
    private static FileReader file;
    private static Scanner in;
    private static Set<String> operators;
    
}

Program Output
Line: 2 3 4 + +
Result: 9
Line: 12 6 / 4 * 4 +
Result: 12
Line: 2 2 3 3 ***
Result: 36
Line: 75 / 5 + 17 -
Result: -11
Line: 4 3 - 5 6 + 4 *
Result: -43
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: 75 / 5 + 17 - Result: -11 Line: 4 3 - 5 6 + 4 * Result: -43 Line: 1 1 + 3 * 4 - 10 ^ Result: 1024
In class we developed code for a Generic Stack. The classes were Node, StackArray, StackRefas wel
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, suchas 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 read the data file below which achieves the output 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 readeach
line as a String. You will need to break up that line into a series of tokens. The String split method is
an easyway to create anarray of String tokens. For example, after reading the line "12 6/4*4+"
split will produce anarray 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. Todetermine if
the token is an operand, you may want to create a Set<String>of all 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 try to 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 wel 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, suchas 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 read the data file below which achieves the output 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 readeach line as a String. You will need to break up that line into a series of tokens. The String split method is an easyway to create anarray of String tokens. For example, after reading the line "12 6/4*4+" split will produce anarray 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. Todetermine if the token is an operand, you may want to create a Set<String>of all 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 try to 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 ^
Expert Solution
Step 1

Please follow the link:

https://www.bartleby.com/questions-and-answers/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-/af88e3f4-c3f8-418b-9dfd-2091a6834bb8

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
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