Compilation failed Compilation failed zyLabs UnitTest.java:35: error: cannot find symbol if (Util.equals (util.getRoot(), bxt.getRoot ( ) ) ) { symbol: method getRoot () location: variable bxt of type BXT zyLabs UnitTest.java:39: error: cannot find symbol new PrintTree() .print (bxt.getRoot () ); symbol: method getRoot () location: variable bxt of type BXT 2 errors 2:Unit test Compilation failed Compilation failed zyLabs UnitTest.java:16: error: cannot find symbol if (Util.equals (util.getRoot(), bxt.getRoot())) { symbol: method getRoot () location: variable bxt of type BXT zyLabs UnitTest.java:20: error: cannot find symbol symbol: new PrintTree() .print (bxt.getRoot () ); method getRoot () location: variable bxt of type BXT 2 errors

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help fixing this Java code to output as it's explained in the image below:

import java.util.Stack;

public class BXT {
    private TreeNode root;

    public void buildTree(String postfix) {
        Stack<TreeNode> stack = new Stack<>();
        String[] tokens = postfix.split(" ");

        for (String token : tokens) {
            if (isOperator(token)) {
                TreeNode right = stack.pop();
                TreeNode left = stack.pop();
                stack.push(new TreeNode(token, left, right));
            } else {
                stack.push(new TreeNode(token));
            }
        }

        root = stack.pop();
    }

    public double evaluateTree() {
        return evaluateTree(root);
    }

    private double evaluateTree(TreeNode node) {
        if (isOperator(node.getData())) {
            double left = evaluateTree(node.getLeft());
            double right = evaluateTree(node.getRight());
            switch (node.getData()) {
                case "+": return left + right;
                case "-": return left - right;
                case "*": return left * right;
                case "/": return left / right;
                default: throw new IllegalArgumentException("Invalid operator: " + node.getData());
            }
        } else {
            return Double.parseDouble(node.getData());
        }
    }

    public void infix() {
        infix(root);
        System.out.println();
    }

    private void infix(TreeNode node) {
        if (node != null) {
            infix(node.getLeft());
            System.out.print(node.getData() + " ");
            infix(node.getRight());
        }
    }

    public void prefix() {
        prefix(root);
        System.out.println();
    }

    private void prefix(TreeNode node) {
        if (node != null) {
            System.out.print(node.getData() + " ");
            prefix(node.getLeft());
            prefix(node.getRight());
        }
    }

    public void postfix() {
        postfix(root);
        System.out.println();
    }

    private void postfix(TreeNode node) {
        if (node != null) {
            postfix(node.getLeft());
            postfix(node.getRight());
            System.out.print(node.getData() + " ");
        }
    }

    private boolean isOperator(String token) {
        return token.equals("+") || token.equals("-") || token.equals("*") || token.equals("/");
    }
}

//These codes are involved with the above code that needs fixing

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;
   }
  }

Compilation failed
Compilation failed
zyLabs UnitTest.java:35: error: cannot find symbol
if (Util.equals (util.getRoot(), bxt.getRoot ( ) ) ) {
symbol: method getRoot ()
location: variable bxt of type BXT
zyLabs UnitTest.java:39: error: cannot find symbol
new PrintTree<String>() .print (bxt.getRoot () );
symbol: method getRoot ()
location: variable bxt of type BXT
2 errors
2:Unit test
Compilation failed
Compilation failed
zyLabs UnitTest.java:16: error: cannot find symbol
if (Util.equals (util.getRoot(), bxt.getRoot())) {
symbol: method getRoot ()
location: variable bxt of type BXT
zyLabs UnitTest.java:20: error: cannot find symbol
symbol:
new PrintTree<String>() .print (bxt.getRoot () );
method getRoot ()
location: variable bxt of type BXT
2 errors
Transcribed Image Text:Compilation failed Compilation failed zyLabs UnitTest.java:35: error: cannot find symbol if (Util.equals (util.getRoot(), bxt.getRoot ( ) ) ) { symbol: method getRoot () location: variable bxt of type BXT zyLabs UnitTest.java:39: error: cannot find symbol new PrintTree<String>() .print (bxt.getRoot () ); symbol: method getRoot () location: variable bxt of type BXT 2 errors 2:Unit test Compilation failed Compilation failed zyLabs UnitTest.java:16: error: cannot find symbol if (Util.equals (util.getRoot(), bxt.getRoot())) { symbol: method getRoot () location: variable bxt of type BXT zyLabs UnitTest.java:20: error: cannot find symbol symbol: new PrintTree<String>() .print (bxt.getRoot () ); method getRoot () location: variable bxt of type BXT 2 errors
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education