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.




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.
Answered 2 days AfterMay 15, 2021

Answer To: Lab 6 – Working with Trees (30pts) Be sure to submit all questions and the two parts of this...

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

    
    
    
binary tree/.project

     binery tree
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
binary 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=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
binary tree/bin/Binery/ArrayIterator.class
package Binery;
public synchronized class
ArrayIterator implements java.util.Iterator {
private int DEFAULT_CAPACITY;
private int count;
private int current;
private Object[] items;
public void ArrayIterator();
public void add(Object);
public boolean hasNext();
public Object next();
public void remove() throws UnsupportedOperationException;
private void expandCapacity();
}
binary tree/bin/Binery/BackPainAnalyzer.class
package Binery;
public synchronized class BackPainAnalyzer {
public void BackPainAnalyzer();
public static void main(String[]);
}
binary tree/bin/Binery/BackPainExpert.class
package Binery;
public synchronized class BackPainExpert {
private LinkedBinaryTree tree;
public void BackPainExpert();
public void diagnose();
}
binary tree/bin/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();
}
binary tree/bin/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(ArrayIterator);
}
binary tree/bin/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);
}
binary tree/bin/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;
}
binary tree/bin/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);
}
binary tree/bin/Binery/ElementNotFoundException.class
package Binery;
public synchronized class ElementNotFoundException extends RuntimeException {
public void ElementNotFoundException(String);
}
binary tree/bin/Binery/EmptyCollectionException.class
package Binery;
public synchronized class EmptyCollectionException extends RuntimeException {
public void EmptyCollectionException(String);
}
binary tree/bin/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();
}
binary tree/bin/Binery/LinkedQueue.class
package Binery;
public synchronized class LinkedQueue {
public void LinkedQueue();
public void enqueue(BTNode);
}
binary tree/src/Binery/ArrayIterator.java
binary tree/src/Binery/ArrayIterator.java
package Binery;
//********************************************************************
//  ArrayIterator.java       Java Foundations
//
//  Represents an iterator over the elements of a collection.
//********************************************************************
import java.util.*;
public class ArrayIterator implements Iterator
{
   private int DEFAULT_CAPACITY = 10;
   private int count;    // the number of elements in the iterator
   private int current;  // the current position in the iteration
   private T[] items;    // the iterator's storage for elements
   //-----------------------------------------------------------------
   //  Sets up this iterator.
   //-----------------------------------------------------------------
   @SuppressWarnings("unchecked")
public ArrayIterator()
   {
      items = (T[]) (new Object[DEFAULT_CAPACITY]);
      count = 0;
      current = 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 (current < 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();
      current++;
      return items[current - 1];
   }
   //-----------------------------------------------------------------
   //  The remove operation is not supported in this collection.
   //-----------------------------------------------------------------
   public void remove() throws UnsupportedOperationException
   {
     throw new UnsupportedOperationException();
   }
   //-----------------------------------------------------------------
   //  Exapands the capacity of the storage array
   //-----------------------------------------------------------------
   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;
   }
}
binary tree/src/Binery/BackPainAnalyzer.java
binary tree/src/Binery/BackPainAnalyzer.java
package Binery;
//********************************************************************
//  BackPainAnalyzer.java       Java Foundations
//
//  Demonstrates the use of a binary tree.
//********************************************************************
public class BackPainAnalyzer
{
   //-----------------------------------------------------------------
   //  Asks questions of the user to diagnose a medical problem.
   //-----------------------------------------------------------------
   public static void main (String[] args)
   {
      BackPainExpert expert = new BackPainExpert();
      expert.diagnose();
   }
}
binary tree/src/Binery/BackPainExpert.java
binary...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here