Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Lab 6 – Working with Trees (30pts) Be sure to submit all questions and the two parts of this assignment by the due date. You may zip all of the files together to submit on blackboard. Code Activities:...

1 answer below »

Lab 6 – Working with Trees (30pts)

Be sure to submit all questions and the two parts of this assignment by the due date. You may zip all of the files together to submit on blackboard.

Code Activities:

Part 1 - Tree Height (10 pts)

Add a method to the LinkedBinaryTree class that returns the height of a tree. Like many tree methods, this will require a fairly simple method in LinkedBinaryTree and another method in BTNode that does most of the work. First, check to see if the root is null. If it is, then the tree is obviously empty and return 0. If it is not null, return root.height().

Part 2 - Decision Tree (20 pts)

Create a decision tree for a topic of your choice. Examples: How to choose a college major? How to select a car? How to determine what to eat for dinner? You must have at least 14 questions that you could potentially ask the user. You will need to add a few missing methods to get your program to work correctly. Take a look at Figure 19.13 in relation to the String variables in BackPainExpert.java.


Please make sure the assignment is done in java and that Part 2 has 14 questions asked.

Answered 2 days After May 15, 2021

Solution

Pulkit answered on May 17 2021
144 Votes
binary tree/.classpath

    
    
    
inary tree/.project

     binery tree
    
    
    
    
        
             org.eclipse.jdt.core.javabuilde
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
inary tree/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=e
o
org.eclipse.jdt.core.compiler.problem.enumIdentifier=e
o
org.eclipse.jdt.core.compiler.source=1.8
inary tree
in/Binery/A
ayIterator.class
package Binery;
public synchronized class A
ayIterator implements java.util.Iterator {
private int DEFAULT_CAPACITY;
private int count;
private int cu
ent;
private Object[] items;
public void A
ayIterator();
public void add(Object);
public boolean hasNext();
public Object next();
public void remove() throws UnsupportedOperationException;
private void expandCapacity();
}
inary tree
in/Binery/BackPainAnalyzer.class
package Binery;
public synchronized class BackPainAnalyzer {
public void BackPainAnalyzer();
public static void main(String[]);
}
inary tree
in/Binery/BackPainExpert.class
package Binery;
public synchronized class BackPainExpert {
private LinkedBinaryTree tree;
public void BackPainExpert();
public void diagnose();
}
inary tree
in/Binery/BinaryTree.class
package Binery;
public abstract interface BinaryTree extends Iterable {
public abstract Object getRootElement();
public abstract BinaryTree getLeft();
public abstract BinaryTree getRight();
public abstract boolean contains(Object);
public abstract Object find(Object);
public abstract boolean isEmpty();
public abstract int size();
public abstract String toString();
}
inary tree
in/Binery/BTNode.class
package Binery;
public synchronized class BTNode {
protected Object element;
protected BTNode left;
protected BTNode right;
public void BTNode(Object);
public Object getElement();
public void setElement(Object);
public BTNode getLeft();
public void setLeft(BTNode);
public BTNode getRight();
public void setRight(BTNode);
public BTNode find(Object);
public int count();
public static int height(javax.xml.soap.Node);
public void inorder(A
ayIterator);
}
inary tree
in/Binery/DecisionTree$BinTree.class
package Binery;
synchronized class DecisionTree$BinTree {
private int nodeID;
private String questOrAns;
private DecisionTree$BinTree yesBranch;
private DecisionTree$BinTree noBranch;
public void DecisionTree$BinTree(DecisionTree, int, String);
}
inary tree
in/Binery/DecisionTree$DecisionTreeApp.class
package Binery;
synchronized class DecisionTree$DecisionTreeApp {
static java.io.BufferedReader keyboardInput;
static DecisionTree newTree;
static void ();
void DecisionTree$DecisionTreeApp();
public static void main(String[]) throws java.io.IOException;
static void generateTree();
static void queryTree() throws java.io.IOException;
static void optionToExit() throws java.io.IOException;
}
inary tree
in/Binery/DecisionTree.class
package Binery;
synchronized class DecisionTree {
static java.io.BufferedReader keyboardInput;
DecisionTree$BinTree rootNode;
static void ();
public void DecisionTree();
public void createRoot(int, String);
public void addYesNode(int, int, String);
private boolean searchTreeAndAddYesNode(DecisionTree$BinTree, int, int, String);
public void addNoNode(int, int, String);
private boolean searchTreeAndAddNoNode(DecisionTree$BinTree, int, int, String);
public void queryBinTree() throws java.io.IOException;
private void queryBinTree(DecisionTree$BinTree) throws java.io.IOException;
private void askQuestion(DecisionTree$BinTree) throws java.io.IOException;
public void outputBinTree();
private void outputBinTree(String, DecisionTree$BinTree);
}
inary tree
in/Binery/ElementNotFoundException.class
package Binery;
public synchronized class ElementNotFoundException extends RuntimeException {
public void ElementNotFoundException(String);
}
inary tree
in/Binery/EmptyCollectionException.class
package Binery;
public synchronized class EmptyCollectionException extends RuntimeException {
public void EmptyCollectionException(String);
}
inary tree
in/Binery/LinkedBinaryTree.class
package Binery;
public synchronized class LinkedBinaryTree implements BinaryTree {
protected BTNode root;
public void LinkedBinaryTree();
public void LinkedBinaryTree(Object);
public void LinkedBinaryTree(Object, LinkedBinaryTree, LinkedBinaryTree);
public Object getRootElement();
public LinkedBinaryTree getLeft();
public Object find(Object);
public int size();
public java.util.Iterator iterator();
public BinaryTree getRight();
public boolean contains(Object);
public boolean isEmpty();
}
inary tree
in/Binery/LinkedQueue.class
package Binery;
public synchronized class LinkedQueue {
public void LinkedQueue();
public void enqueue(BTNode);
}
inary tree/src/Binery/A
ayIterator.java
inary tree/src/Binery/A
ayIterator.java
package Binery;
********************************************************************
  A
ayIterator.java       Java Foundations
  Represents an iterator over the elements of a collection.
********************************************************************
import java.util.*;
public class A
ayIterato
T> implements Iterato
T
{
   private int DEFAULT_CAPACITY = 10;
   private int count;    
 the number of elements in the iterato
   private int cu
ent;  
 the cu
ent position in the iteration
   private T[] items;    
 the iterator's storage for elements
   
-----------------------------------------------------------------
   
  Sets up this iterator.
   
-----------------------------------------------------------------
   @SuppressWarnings("unchecked")
public A
ayIterator()
   {
      items = (T[]) (new Object[DEFAULT_CAPACITY]);
      count = 0;
      cu
ent = 0;
   }
   
-----------------------------------------------------------------
   
  Adds the specified item to this iterator.
   
-----------------------------------------------------------------
   public void add (T item)
   {
      if (count == items.length)
         expandCapacity();
      items[count] = item;
      count++;
   }
   
-----------------------------------------------------------------
   
  Returns true if this iterator has at least one more element to
   
  deliver in the iteration.
   
-----------------------------------------------------------------
   public boolean hasNext()
   {
      return (cu
ent < count);
   }
   
-----------------------------------------------------------------
   
  Returns the next element in the iteration. If there are no more
   
  elements in this iteration, a NoSuchElementException is thrown.
   
-----------------------------------------------------------------
   public T next()
   {
      if (! hasNext())
         throw new NoSuchElementException();
      cu
ent++;
      return items[cu
ent - 1];
   }
   
-----------------------------------------------------------------
   
  The remove operation is not supported in this collection.
   
-----------------------------------------------------------------
   public void remove() throws UnsupportedOperationException
   {
     throw new UnsupportedOperationException();
   }
   
-----------------------------------------------------------------
   
  Exapands the capacity of the storage a
ay
   
-----------------------------------------------------------------
   private void expandCapacity()
   {
       
      @SuppressWarnings("unchecked")
    T[] larger = (T []) (new Object[items.length*2]);
      int location = 0;
      for (T element : items)
         larger[location++] = element;
      items = larger;
   }
}
inary tree/src/Binery/BackPainAnalyzer.java
inary tree/src/Binery/BackPainAnalyzer.java
package Binery;
********************************************************************
  BackPainAnalyzer.java       Java Foundations
  Demonstrates the use of a binary tree.
********************************************************************
public class BackPainAnalyze
{
   
-----------------------------------------------------------------
   
  Asks questions of the user to diagnose a medical problem.
   
-----------------------------------------------------------------
   public static void main (String[] args)
   {
      BackPainExpert expert = new BackPainExpert();
      expert.diagnose();
   }
}
inary tree/src/Binery/BackPainExpert.java
inary...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here