Question: Project: Expression Trees IN JAVA This project is adapted from Project 1 of Chapter 9 of the textbook. It deals with a simple kind of

Project: Expression Trees IN JAVA This project is adapted from Project 1 of Chapter 9 of the textbook. It deals with a simple kind of expression trees, in which there are two kinds of nodes: (a) Leaf nodes, which contain a real number as their clement; and (b) Non-leaf nodes, which have exactly two children and contain one of these characters as their element: +, -, * and /. These characters represent arithmetic operations and have usual interpretations. Implement a class for expression trees with these operations: (a) A constructor that builds an expression tree. It accepts a String that represents a grammatically correct expression as its sole input. Hint: refer to Chapter 6.2 and slides on evaluating expressions. (b) A recursive method named eval that evaluates a non-empty expression tree using these rules: i. If the tree has only one node (which must be a leaf), then eval returns the real number that is the node's clement; ii. If the tree has more than one node and the root contains op where op is one of +, -, * and /, then eval first evaluates the sub-trees of the root and returns the real number obtained by performing operation op on the results from evaluating the sub-trees. (c) A recursive method named infix that output the expression represented by a non-empty expression tree to a String in infix format. (d) A recursive method named postfix that outputs the expression represented by a non-empty expression tree in postfix format. You also need to write another class that applies the operations of the above class.

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 Databases Questions!