
I need help with this Java problem to output as it's explained in the image below:
NodeInterface.java (Don't edit)
interface NodeInterface<T>{
T getData();
NodeInterface<T> getLeft();
NodeInterface<T> getRight();
}
/**
*
* TreeNode.java: TreeNode class. // (Don't edit)
*/
public class TreeNode implements NodeInterface<String>
{
private String value;
private TreeNode left, right;
public TreeNode(String initValue)
{
value = initValue;
left = null;
right = null;
}
public TreeNode(String initValue, TreeNode initLeft, TreeNode initRight)
{
value = initValue;
left = initLeft;
right = initRight;
}
public String getData()
{
return value;
}
public TreeNode getLeft()
{
return left;
}
public TreeNode getRight()
{
return right;
}
public void setValue(String theNewValue)
{
value = theNewValue;
}
public void setLeft(TreeNode theNewLeft)
{
left = theNewLeft;
}
public void setRight(TreeNode theNewRight)
{
right = theNewRight;
}
}
![Binary Expression Tree
A binary expression tree is a specific kind of a binary tree used to represent expressions. The leaves of the binary expression tree are
operands, and the interior nodes contain operators. Assume the possible operators including +, -,,, and % and operands are numerical
data. The following figures illustrate binary expression trees for the expressions with different notations:
Example 1
Postfix Exp: 14-5/
BXT:
[/]
[14] [-5]
Infix order: 14 / -5
Prefix order: / 14-5
Evaluates to -2.8
Example 2
Postfix Exp: 203-4+*
Example 3
Postfix Exp: 23+5/45-*
BXT:
BXT:
[[*]
[20]
[+]
[/1
[-]
/\
,
.
ハ
[3]
[-4]
[+]
[5] [4]
[5]
1
Infix order: 203-4
Prefix order: 20 + 3-4
Evaluates to -20.0
[2]
[3]
Infix order: 2 + 3 / 54-5
Prefix order: * / +235-45
Evaluates to -1.0
Your Tasks:
For this assignment, you will build a binary expression tree, display it, and evaluate it. You will encapsulate the behavior in a BXT class. The
driver class, tree node, and the BXT class are provided. Please implement appropriate methods in BXT class to build, display, and evaluate a
tree.
Requirements for each method:
Build a BXT: You need to change the string into a tree. The argument string is in postfix notation.
Display Infix and Prefix orders
Infix is characterized by the placement of operators between operands;
Prefix expression notation requires that all operators precede the two operands that they work on;
Postfix requires that its operators come after the corresponding operands. See following examples:
Infix, Prefix, and Postfix Orders
Infix Expression Prefix Expression Postfix Expression
A+B
+AB
AB+
A+B˚C
+ A*BC
ABC*+
Evaluating the Expression
Do this recursively. If the node is an operator, recursively evaluate the left child and the right child, and return the result. Else the node is a
number, so it can be converted into a double, and returned.
Requirements for your application:
Please design an application to meet the following specific methods:
.
build Tree(String str): The argument string is in postfix notation. Build the tree as specified in the document-refer to examples 1,2 and
3;
• eveluate Tree(): Do this recursively. If the node is an operator, recursively evaluate the left child and the right child, and return the result.
Else the node is a number, so it can be converted into a double, and returned.
• infix(): Infix is characterized by the placement of operators between operands;
prefix(): Prefix expression notation requires that all operators precede the two operands that they work on;
posfix(): Postfix requires that its operators come after the corresponding operands](https://content.bartleby.com/qna-images/question/4e135d5c-f867-4afd-9f0d-b505f4f19664/3ffc3ae3-6f3b-43c1-b73e-263dda7ba806/8hsuz1_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Hi, I am a bit lost on how to do this coding assignment. It would be great if someone could help me fill in the MyStack.java file with the given information. All the information is in the pictures. Thank you!arrow_forwardThere is an error for type in ProgramNode.java. Please fix the error and show the fixed code for ProgramNode.java with the screenshot of the working code.arrow_forwardAdd missing code to turn this class a singleton in Java package com.gamingroom; import java.util.ArrayList;import java.util.List; /** * A singleton service for the game engine */public class GameService { /** * A list of the active games */ private static List<Game> games = new ArrayList<Game>(); /* * Holds the next game identifier */ private static long nextGameId = 1; // FIXME: Add missing pieces to turn this class a singleton /** * Construct a new game instance * * @param name the unique name of the game * @return the game instance (new or existing) */ public Game addGame(String name) { // a local game instance Game game = null; // FIXME: Use iterator to look for existing game with same name // if found, simply return the existing instance // if not found, make a new game instance and add to list of games if (game == null) { game = new Game(nextGameId++, name); games.add(game); } // return the new/existing game instance to the caller return…arrow_forward
- Here is my code in Java: import java.util.Scanner; import java.util.HashMap; public class Inventory { /** This class demonstrates the inventory */ //Declarations Of inventory static final int LightBulb60W = 1; static final int LightBulb100W = 2; static final int BoltM5 = 3; static final int BoltM8 = 4; static final int Hose25 = 5; static final int Hose50 = 6; public static void main (String [] args) { //Scanner Object @SuppressWarnings("resource") Scanner keyboard = new Scanner(System.in); //Variables int month; int day; int year; double units; double cost = 0; //Declarations int total; HashMap<Integer, String> productMap = new HashMap<>(); productMap.put(1,"Light Bulb 60W"); productMap.put(2,"Light Bulb 100W"); productMap.put(3,"Bolt M5"); productMap.put(4,"Bolt M8"); productMap.put(5,"Hose 25 feet"); productMap.put(6,"Hose 50 feet 60W"); while(true){ //Prints out inventory System.out.println("The Inventory: "); System.out.println("1…arrow_forwardI need help with this Java problem to output as it's explained in the image below: public class BST { private Node root; public void insert(int data) { root = insertRec(root, data); } private Node insertRec(Node root, int data) { if (root == null) { root = new Node(data); return root; } if (data < root.data) { root.left = insertRec(root.left, data); } else if (data > root.data) { root.right = insertRec(root.right, data); } return root; } public int getHeight() { return getHeightRec(root); } private int getHeightRec(Node root) { if (root == null) { return 0; } else { int leftHeight = getHeightRec(root.left); int rightHeight = getHeightRec(root.right); return Math.max(leftHeight, rightHeight) + 1; } } public int search(int data) { return searchRec(root, data, 0); }…arrow_forwardRun the program to tell me there is an error, BSTChecker.java:3: error: duplicate class: Node class Node { ^ BSTChecker.java:63: error: class LabProgram is public, should be declared in a file named LabProgram.java public class LabProgram { ^ 2 errors This is my program, please fix it. import java.util.*; class Node { int key; Node left, right; public Node(int key) { this.key = key; left = right = null; } } class BSTChecker { public static Node checkBSTValidity(Node root) { return checkBSTValidityHelper(root, null, null); } private static Node checkBSTValidityHelper(Node node, Integer min, Integer max) { if (node == null) { return null; } if ((min != null && node.key <= min) || (max != null && node.key >= max)) { return node; } Node leftResult = checkBSTValidityHelper(node.left, min, node.key); if (leftResult != null) { return leftResult; } Node rightResult = checkBSTValidityHelper(node.right, node.key, max); if (rightResult != null) { return rightResult; }…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





