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

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

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.
Transcribed Image Text: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.
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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Binomial Heap
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar 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