Question: IN JAVA. Write code for ExpressionTest.java and Expression.java and use the stack ADT and LinkedStack to implement the ADT. The program has to be run
IN JAVA. Write code for ExpressionTest.java and Expression.java and use the stack ADT and LinkedStack to implement the ADT. The program has to be run on the command line and look like the output seen below.




Description: We are used to writing arithmetic expressions with the operator between the two operands: a +b or c/d. If we write a+bc, however, we must apply precedence orders to avoid ambiguous evaluation. This type of expression is called infix expression. There are two other types of different but equivalent ways of writing expressions. Infix: X + Y: Operators are written in-between their operands. Infix expression needs extra information to make the order of evaluation of the operators clear: precedence and associativity, brackets ( ). For example, A(B+C)/D. Postfix: X Y +: Operators are written after their operands. The above infix expression can be written using postfix notation as ABC+D/ Prefix: + X Y: Operators are written before their operands. The above infix expression can be written using prefix notation as / A+BCD More examnles of the above three exnressions are given below: You are to implement two class methods that can convert an infix expression to its equivalent postfix and evaluate the postfix expression. A term will be an integer literal. The parameter to your methods will be an array of Strings and so is the return value. Each element of the array can either be an integer literal or a binary operator +/( where is the power operator, xy is xy) You are to implement the class Expression which includes the algorithms convertToPostfix and evaluatePostfix. They are class methods. Class name: Expression Conversion of Infix to Postfix: Method name: String[] convertToPostfix (String[] infixExpression) infixExpression - each element is a token that can be an operator or an integer literal. Operator can be +,,,/, or . This method will convert an infix to a postfix expression. Throw a RuntimeException(msg) if infixExpression is not well-formed or not an integer literal. Conversion of Infix to Postfix: Method name: int evaluatePostfix (String[] posfixExpression) Throw RuntimeException(msg) when postfixException is not well-formed or not an integer literal. You must implement your own generic Stack ADT for this project. What to test? Think of your own cases: correct input, without parentheses or with matched parentheses; and incorrect input (with unmatched parentheses). Your program should catch the error with unmatched parentheses and when one of the operands is missing. Make sure that you deal with all error conditions, for example, pop/top on an empty stack. Write an application named ExpressionTest that will take an integer infix expression(s) from the command line. Using the Expression class to convert and output the equivalent postfix express, and the evaluation of the postfix expression. Required I/O: java ExpressionTest "1 +23" " 10/2" Expression by F. Last 1+23 123+=7 10/2 102/=5 Project report: (PDF format) - Page 1: Cover page with your name, class, project, and due date - Page 2 to 3 : - Section 1 (Project specification): Your ADT description. Description of data structures used and a description of how you implement the ADT - Section 2 (Testing methodology): Description of how you test your ADT, refer to your testing output. Explain why your test cases are rigorous and complete. Demonstrate that you test each method. - Section 3 (Lessons learned): Any other information you wish to include. Turn in: 1. Project report PDF must be named report.pdf and included inside your zip submission. 2. There should be 4 Java source code and the report files: Expression.java ExpressionTest.java StackInterface.java LinkedStack.java report.pdf Compress these files into a single zip file and submit it on Canvas with the following name: p2-s\#.zip where \# is your section \#, 2 or 3. For example: p2-s2.zip, p2-s3.zip Linked Implementation of a Stack / A class of stacks whose entries are stored in a chain of nodes. */ public final class LinkedStack implements Stacklnterface \{ private Node topNode; // References the first node in the chain public LinkedStack() \{ topNode = null; \} // end default constructor // // private class Node \{ private T data; // Entry in stack private Node next; // Link to next node // \} // end Node \} // end LinkedStack LISTING 6-1 An outline of a linked implementation of the ADT stack P Pearson Copyright (c) 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved /** An interface for the ADT stack. */ public interface StackInterface \{ // Adds a new entry to the top of this stack. @param newEntry An object to be added to the stack. */ public void push(T newEntry); /** Removes and returns this stack's top entry. @return The object at the top of the stack. @throws EmptyStackException if the stack is empty before the operation. */ public T pop(); / Retrieves this stack's top entry. @return The object at the top of the stack. @throws EmptyStackException if the stack is empty. */ public T peek(); / Detects whether this stack is empty. @return True if the stack is empty. / public boolean isEmpty(); / Removes all entries from this stack. */ public void clear(); \}// end StackInterface Description: We are used to writing arithmetic expressions with the operator between the two operands: a +b or c/d. If we write a+bc, however, we must apply precedence orders to avoid ambiguous evaluation. This type of expression is called infix expression. There are two other types of different but equivalent ways of writing expressions. Infix: X + Y: Operators are written in-between their operands. Infix expression needs extra information to make the order of evaluation of the operators clear: precedence and associativity, brackets ( ). For example, A(B+C)/D. Postfix: X Y +: Operators are written after their operands. The above infix expression can be written using postfix notation as ABC+D/ Prefix: + X Y: Operators are written before their operands. The above infix expression can be written using prefix notation as / A+BCD More examnles of the above three exnressions are given below: You are to implement two class methods that can convert an infix expression to its equivalent postfix and evaluate the postfix expression. A term will be an integer literal. The parameter to your methods will be an array of Strings and so is the return value. Each element of the array can either be an integer literal or a binary operator +/( where is the power operator, xy is xy) You are to implement the class Expression which includes the algorithms convertToPostfix and evaluatePostfix. They are class methods. Class name: Expression Conversion of Infix to Postfix: Method name: String[] convertToPostfix (String[] infixExpression) infixExpression - each element is a token that can be an operator or an integer literal. Operator can be +,,,/, or . This method will convert an infix to a postfix expression. Throw a RuntimeException(msg) if infixExpression is not well-formed or not an integer literal. Conversion of Infix to Postfix: Method name: int evaluatePostfix (String[] posfixExpression) Throw RuntimeException(msg) when postfixException is not well-formed or not an integer literal. You must implement your own generic Stack ADT for this project. What to test? Think of your own cases: correct input, without parentheses or with matched parentheses; and incorrect input (with unmatched parentheses). Your program should catch the error with unmatched parentheses and when one of the operands is missing. Make sure that you deal with all error conditions, for example, pop/top on an empty stack. Write an application named ExpressionTest that will take an integer infix expression(s) from the command line. Using the Expression class to convert and output the equivalent postfix express, and the evaluation of the postfix expression. Required I/O: java ExpressionTest "1 +23" " 10/2" Expression by F. Last 1+23 123+=7 10/2 102/=5 Project report: (PDF format) - Page 1: Cover page with your name, class, project, and due date - Page 2 to 3 : - Section 1 (Project specification): Your ADT description. Description of data structures used and a description of how you implement the ADT - Section 2 (Testing methodology): Description of how you test your ADT, refer to your testing output. Explain why your test cases are rigorous and complete. Demonstrate that you test each method. - Section 3 (Lessons learned): Any other information you wish to include. Turn in: 1. Project report PDF must be named report.pdf and included inside your zip submission. 2. There should be 4 Java source code and the report files: Expression.java ExpressionTest.java StackInterface.java LinkedStack.java report.pdf Compress these files into a single zip file and submit it on Canvas with the following name: p2-s\#.zip where \# is your section \#, 2 or 3. For example: p2-s2.zip, p2-s3.zip Linked Implementation of a Stack / A class of stacks whose entries are stored in a chain of nodes. */ public final class LinkedStack implements Stacklnterface \{ private Node topNode; // References the first node in the chain public LinkedStack() \{ topNode = null; \} // end default constructor // // private class Node \{ private T data; // Entry in stack private Node next; // Link to next node // \} // end Node \} // end LinkedStack LISTING 6-1 An outline of a linked implementation of the ADT stack P Pearson Copyright (c) 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved /** An interface for the ADT stack. */ public interface StackInterface \{ // Adds a new entry to the top of this stack. @param newEntry An object to be added to the stack. */ public void push(T newEntry); /** Removes and returns this stack's top entry. @return The object at the top of the stack. @throws EmptyStackException if the stack is empty before the operation. */ public T pop(); / Retrieves this stack's top entry. @return The object at the top of the stack. @throws EmptyStackException if the stack is empty. */ public T peek(); / Detects whether this stack is empty. @return True if the stack is empty. / public boolean isEmpty(); / Removes all entries from this stack. */ public void clear(); \}// end StackInterface