Please help! // TreeNode.java class TreeNode { T item; TreeNode leftChild; TreeNode rightChild; public TreeNode(T newItem) { // Initializes tree node with item and no children. item = newItem; leftChild = null; rightChild = null; } // end constructor public TreeNode(T newItem, TreeNode left, TreeNode right) { // Initializes tree node with item and // the left and right children references. item = newItem; leftChild = left; rightChild = right; } // end constructor } // end TreeNode // BinaryTreeBasis.java public abstract class BinaryTreeBasis { protected TreeNode root; public BinaryTreeBasis() { root = null; } // end default constructor public BinaryTreeBasis(T rootItem) { root = new TreeNode(rootItem, null, null); } // end constructor public boolean isEmpty() { // Returns true if the tree is empty, else returns false. return root == null; } // end isEmpty public void makeEmpty() { // Removes all nodes from the tree. root = null; } // end makeEmpty public T getRootItem() throws TreeException { // Returns the item in the tree's root. if (root == null) { throw new TreeException("TreeException: Empty tree"); } else { return root.item; } // end if } // end getRootItem public abstract void setRootItem(T newItem); // Throws UnsupportedOperationException if operation // is not supported. } // end BinaryTreeBasi
Please help!
// TreeNode.java
class TreeNode<T> {
T item;
TreeNode<T> leftChild;
TreeNode<T> rightChild;
public TreeNode(T newItem) {
// Initializes tree node with item and no children.
item = newItem;
leftChild = null;
rightChild = null;
} // end constructor
public TreeNode(T newItem,
TreeNode<T> left, TreeNode<T> right) {
// Initializes tree node with item and
// the left and right children references.
item = newItem;
leftChild = left;
rightChild = right;
} // end constructor
} // end TreeNode
// BinaryTreeBasis.java
public abstract class BinaryTreeBasis<T> {
protected TreeNode<T> root;
public BinaryTreeBasis() {
root = null;
} // end default constructor
public BinaryTreeBasis(T rootItem) {
root = new TreeNode<T>(rootItem, null, null);
} // end constructor
public boolean isEmpty() {
// Returns true if the tree is empty, else returns false.
return root == null;
} // end isEmpty
public void makeEmpty() {
// Removes all nodes from the tree.
root = null;
} // end makeEmpty
public T getRootItem() throws TreeException {
// Returns the item in the tree's root.
if (root == null) {
throw new TreeException("TreeException: Empty tree");
}
else {
return root.item;
} // end if
} // end getRootItem
public abstract void setRootItem(T newItem);
// Throws UnsupportedOperationException if operation
// is not supported.
} // end BinaryTreeBasis
![public interface GameTree {
7
8
9.
10
11
12
13
14
15
16
17
18
19
20
21
22
public void startGame(String question, String yesAnswer, String noAnswer);
// Starts playing the game by creating a game tree of three nodes.
// The root contains the question, the root's left child contains the yesAnswer,
// and the root's right child contains the noAnswer.
// Precondition: question is the question to ask.
//
//
// Postcondition: A minimal game tree is created.
// Throws: None.
yesAnswer is the answer to the question for yes.
noAnswer is the answer to the question for no.
public void newRound();
// Starts a new round of the game.
// Precondition: A game tree exists.
// Postcondition: Current position in the game tree is (re)set to the root.
// Throws: None.
23
24
25
public void endGame();
// Ends the game.
// Precondition: None.
// Postcondition: A message is printed to indicate end of game.
// Throws: None.
26
27
28
29
30
31
32
33
public void moveYes() throws TreeException;
// Moves to next step if the user answers yes.
// Precondition: None.
// Postcondition: None.
// Throws: TreeException is thrown if not able to move to next step.
34
35
36
public void moveNo() throws TreeException;
// Moves to next step if the user answers no.
// Precondition: None.
// Postcondition: None.
// Throws: TreeException is thrown if not able to move to next step.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public String getQuestion() throws TreeException;
// Obtains current question from the game tree.
// Precondition: Current node should contain a question.
// Postcondition: Current question is returned.
// Throws: TreeException is thrown if not able to get question.
public void setQuestion(String question, String answer);
// Sets the question provided by the player into the game tree.
// Precondition: question is the question entered by the player.
//
// Postcondition: The question and answers are set up correctly.
// Throws: None.
answer is the correct answer provided by the player.
public String getAnswer() throws TreeException;
// Obtains current answer from the game tree.
// Precondition: Current node should contain an answer.
// Postcondition: Current question is returned.
// Throws: TreeException is thrown if not able to get answer.
60
61
62
63
64
65
66 }
67
public boolean isQuestion();
// Checks if current node is question node
// Precondition: None.
// Postcondition: Returns true if current node is question node.
// Throws: None.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0b7cc003-5e41-4919-949f-52a01644d9f6%2F75d8c1e8-fc2c-45f3-8245-68cfe7b96530%2Fonwuw1_processed.png&w=3840&q=75)
![1. Implement an ADT GameTree that extends the abstract class BinaryTreeBasis provided
in the textbook.
2. Separate the implementation of ADT GameTree from its interface.
3. Develop the application (i.e., a driver program) that uses the ADT GameTree to solve
the problem.
4. The following files are provided, and it is required that they have to be used:
GameTree.java: The game tree interface
BinaryTreeBasis.java: from the textbook
TreeNode.java: from the textbook
TreeException.java: from the textbook
5. You are not allowed to modify the files provided to you except adding package
information if used.
6. Only methods specified in the interface can be declared public in the implementation.
Any other auxiliary method in the implementation should be declared private.
7. In summary, all you need to develop are two java files:
The implementation of the interface that also extends the tree's base class
The application (driver) program that contains a loop to play the game until quit.
Testing
Test the following test cases
YES YES
YES NO
NO YES
NO NO
YES YES (again, just in case)
NO YES (again, just in case)
YES NO YES
YES N ΝΟ
ΝΟ ΝΟΥES
NO NO NO
o Design a test case with at least 4 YES's or NO's](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0b7cc003-5e41-4919-949f-52a01644d9f6%2F75d8c1e8-fc2c-45f3-8245-68cfe7b96530%2Fz3p82gt_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)