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

# GameTree Interface Documentation

The `GameTree` interface defines operations for creating and interacting with a decision-based game tree structure. This interface includes methods for starting and managing a game, moving through the tree, and retrieving or setting questions and answers within the tree.

## Methods:

### `void startGame(String question, String yesAnswer, String noAnswer)`
- **Description**: Initializes the game by creating a tree with three nodes. The root node contains a question, its left child stores the 'yes' answer, and the right child stores the 'no' answer.
- **Preconditions**: 
  - `question` is the query to pose.
  - `yesAnswer` is the response for a 'yes'.
  - `noAnswer` is the response for a 'no'.
- **Postconditions**: A minimal game tree is generated.
- **Throws**: None.

### `void newRound()`
- **Description**: Starts a new game round by resetting the tree’s position to the root.
- **Preconditions**: A game tree already exists.
- **Postconditions**: The current tree position is reset.
- **Throws**: None.

### `void endGame()`
- **Description**: Ends the current game.
- **Preconditions**: None.
- **Postconditions**: A message is displayed indicating the game's end.
- **Throws**: None.

### `void moveYes() throws TreeException`
- **Description**: Advances to the next step if the response is 'yes'.
- **Preconditions**: None.
- **Postconditions**: None.
- **Throws**: `TreeException` if the next step cannot be taken.

### `void moveNo() throws TreeException`
- **Description**: Advances to the next step if the response is 'no'.
- **Preconditions**: None.
- **Postconditions**: None.
- **Throws**: `TreeException` if the next step cannot be taken.

### `String getQuestion() throws TreeException`
- **Description**: Retrieves the current question from the game tree.
- **Preconditions**: The current node must have a question.
- **Postconditions**: Returns the current question.
- **Throws**: `TreeException` if unable to obtain the question.

### `void setQuestion(String question, String answer)`
- **Description**: Sets a new question in the game tree and links it
Transcribed Image Text:# GameTree Interface Documentation The `GameTree` interface defines operations for creating and interacting with a decision-based game tree structure. This interface includes methods for starting and managing a game, moving through the tree, and retrieving or setting questions and answers within the tree. ## Methods: ### `void startGame(String question, String yesAnswer, String noAnswer)` - **Description**: Initializes the game by creating a tree with three nodes. The root node contains a question, its left child stores the 'yes' answer, and the right child stores the 'no' answer. - **Preconditions**: - `question` is the query to pose. - `yesAnswer` is the response for a 'yes'. - `noAnswer` is the response for a 'no'. - **Postconditions**: A minimal game tree is generated. - **Throws**: None. ### `void newRound()` - **Description**: Starts a new game round by resetting the tree’s position to the root. - **Preconditions**: A game tree already exists. - **Postconditions**: The current tree position is reset. - **Throws**: None. ### `void endGame()` - **Description**: Ends the current game. - **Preconditions**: None. - **Postconditions**: A message is displayed indicating the game's end. - **Throws**: None. ### `void moveYes() throws TreeException` - **Description**: Advances to the next step if the response is 'yes'. - **Preconditions**: None. - **Postconditions**: None. - **Throws**: `TreeException` if the next step cannot be taken. ### `void moveNo() throws TreeException` - **Description**: Advances to the next step if the response is 'no'. - **Preconditions**: None. - **Postconditions**: None. - **Throws**: `TreeException` if the next step cannot be taken. ### `String getQuestion() throws TreeException` - **Description**: Retrieves the current question from the game tree. - **Preconditions**: The current node must have a question. - **Postconditions**: Returns the current question. - **Throws**: `TreeException` if unable to obtain the question. ### `void setQuestion(String question, String answer)` - **Description**: Sets a new question in the game tree and links it
### Instructions for Implementing ADT GameTree

1. **Implementation Requirement**: Develop an ADT GameTree that extends the abstract class `BinaryTreeBasis` provided in the textbook.
   
2. **Separation of Implementation**: The implementation of ADT GameTree must be separated from its interface.

3. **Application Development**: Create a driver program to utilize the ADT GameTree to address the problem at hand.

4. **Provided Files**: You are required to use the following files:
   - `GameTree.java`: The game tree interface
   - `BinaryTreeBasis.java`: From the textbook
   - `TreeNode.java`: From the textbook
   - `TreeException.java`: From the textbook

5. **Modification Restrictions**: You are not permitted to alter the provided files except to add package information if needed.

6. **Method Declaration**:
   - Only methods defined in the interface can be declared public in your implementation.
   - Any additional auxiliary methods should be declared private.

7. **Development Summary**: You need to create two Java files:
   - The implementation file that extends the tree's base class through the interface.
   - An application (driver) program that includes a loop for playing the game until the user decides to quit.

### Testing

- **Objective**: Test the following test cases:
  - YES YES
  - YES NO
  - NO YES
  - NO NO
  - YES YES (retesting to ensure reliability)
  - NO YES (retesting to ensure reliability)
  - YES NO YES
  - YES NO NO
  - NO NO YES
  - NO NO NO
  - Design a test case involving at least four YES's or NO's

These steps and tests are designed to guide the creation and testing of a functional ADT GameTree as part of your coursework.
Transcribed Image Text:### Instructions for Implementing ADT GameTree 1. **Implementation Requirement**: Develop an ADT GameTree that extends the abstract class `BinaryTreeBasis` provided in the textbook. 2. **Separation of Implementation**: The implementation of ADT GameTree must be separated from its interface. 3. **Application Development**: Create a driver program to utilize the ADT GameTree to address the problem at hand. 4. **Provided Files**: You are required to use the following files: - `GameTree.java`: The game tree interface - `BinaryTreeBasis.java`: From the textbook - `TreeNode.java`: From the textbook - `TreeException.java`: From the textbook 5. **Modification Restrictions**: You are not permitted to alter the provided files except to add package information if needed. 6. **Method Declaration**: - Only methods defined in the interface can be declared public in your implementation. - Any additional auxiliary methods should be declared private. 7. **Development Summary**: You need to create two Java files: - The implementation file that extends the tree's base class through the interface. - An application (driver) program that includes a loop for playing the game until the user decides to quit. ### Testing - **Objective**: Test the following test cases: - YES YES - YES NO - NO YES - NO NO - YES YES (retesting to ensure reliability) - NO YES (retesting to ensure reliability) - YES NO YES - YES NO NO - NO NO YES - NO NO NO - Design a test case involving at least four YES's or NO's These steps and tests are designed to guide the creation and testing of a functional ADT GameTree as part of your coursework.
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
  • 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