Question: Create a class called ExpressionTree that takes a string in postfix notation as an argument to the constructor. This class will store this expression and

Create a class called ExpressionTree that takes a string in postfix notation as an argument to the constructor. This class will store this expression and have methods that process the expression. The expression is readonly, can't be changed and the object of type ExpressionTree will represent that particular expression that is passed as argument to the constructor.
Define the following methods
ExpressionTree(String postfix)
Constructor, stores the postfix expression in an instance variable for use in other methods of this class.
boolean parse()
Method that parses the postfix returning true if the expression is in valid postfix notation (more on that below). If the expression is valid, the routine, internally should build a BinaryNode tree and store the root in an instance variable.
BinaryNode getRoot()
Returns the root of the tree or null if either the tree hasn't been built yet (i.e., parse() has not been called) or if parse() returns false negative and thus there is no tree.
int evaluate() throws ArithmeticExpression
Method evaluates the tree stored internally and returns an integer representing the value of the expression. The expression should support addition (+), multiplication (*), subtraction (-) and division(/). Note that division requires two special cases. First, check that you don't do division by 0 and second, make sure that the division is done using integer division (casting values) so that the result is always inter. This expression evaluator is a an integer expression evaluator. What to do when you divide by 0? Do the same that Java does, thrown an exception (ArithmeticException). You must declare this method to thrown this exception.
String infixNotation()
Return an infix notation with parenthesis to enforce order of operations. The terminal nodes of the tree contain values (i.e., number) and thus should not be wrapped in parenthesis. But all other subtrees should be turned into a parenthesized expression. This is in effect an in-order traversal of the tree.
Test-driven development dictates that you should do some testing, then some development, then some testing again, and repeat until all of your code is written and it passes all of your tests. Write test cases for this class that verifies that all the methods work as expected. Your test cases should be stored in a file called ExpressionTreeTest and call all methods in the class. The test cases should execute every line of the code in ExpressionTreefor you to get 100% on testing and coverage.
We strongly recommend you build the test cases first, following the idea of test driven development. Build a list of expressions and know ahead of time what those expressions would evaluate to and how they would be represented in infix notation. Use those examples to build the test cases and run them until all of your code gets 100% functional results (all test cases pass) and you get 100% coverage (all of your lines are executed).
The table below shows some cases that you should consider as you understand this project specification. What other cases would you add? Add a few more examples that cover additional cases. For example, have one expression that divides by 0. Write JUnit test cases based on these expressions.
PostfixInfixEvaluation34+(3+4)734*5+((3*4)+5)17345*+(3+(4*5))2310101023+45*+5/(((2+3)+(4*5))/5)5
Be strategic on how you build this class and how you test it. First, define as many test cases as you think are needed to fully test the behavior of the project. Implement the methods, and run the test cases. Start with the constructor, the parse() method and the getRoot() methods. Write the code, test them. Get those three to pass. Then move to the evaluate() and make sure all test cases pass. Once you are done with that, then write the infix conversion and test that. Build strong test cases to ensure you build all possible cases and to ensure you understand the logic.
I need ExpressionTree and ExpressionTreeTest javas and urgent

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!