Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Purpose: Make a form of a binary search tree called a decision tree. The decision tree stores questions and answers to them so that
Purpose: Make a form of a binary search tree called a decision tree. The decision tree stores questions and answers to them so that a user can be asked the questions, see if the answers to the questions are correct, and add new questions and answers in the event certain answers are found to be incorrect. The program starts by inviting the user to think of an animal and to indicate when the user is ready to proceed. Immediately, the computer guesses that the animal is an elephant. Presumably this guess is incorrect, so the user tells the computer what animal the user was thinking of. The computer learns from its mistake by asking the user to teach it a yes/no question that it can use in the future, to tell the difference between the incorrectly guessed animal, and the correct one. It "remembers" this, and in its enthusiasm invites the user to start another cycle by thinking of another animal, and thus the process continues. After a while, the computer "learns" enough so that it can pretty much figure out any animal that any user might think of. This type of artificial intelligence program is called an expert system, a basic form of machine learning in which an expert "trains" the computer and the results are used by others as a diagnostic tool. Perform the following steps: 1. Use this class definition for the binary tree nodes: class BTNode { String text; BTNode yes; BTNode no; } With this class definition, BTNode objects are used to store either a yes/no question or an animal name. All the nodes at the leaves of the binary tree contain animal names, and their yes/no references are null, because they are endpoints of different lines of questioning. The tree "grows" when a leaf is reached, and the animal name in that node is incorrect. In this case, the node "splits" -- you add two new nodes, and connect them to the tree with the yes/no references of the node containing the incorrect animal name. Now, you replace the incorrect animal name in the text string object member with a question, and put animal names in the two new nodes. 2. Use this pseudo code outline to create your driver program (this lab only requires a driver program): main method() { // make a "root" reference to a BTNode. Name the reference root // set root to a newly created node; set its text member to "elephant", BTNode yes and no references to null // start a "while" loop that runs each cycle of the program // get input from the user -- invite the user to think of an animal which it will try to guess // await the user's response, and break out of the loop if the user declines // declare a reference "p" to traverse the tree, and initialize it to "root" // start a loop to traverse the binary tree // if p.yes is null... //...print p.text as the guessed animal // ask user if this is correct // if correct, brag that answer was found by your program and break from loop // ask user what animal the user was thinking of... //...store what the user replied in a string named A // ask what yes/no question differentiates p,text from A... //...store what the user replied in a string named Q // ask which response is correct for A -- yes or no... //...store what the user replied in a character variable named YesNo // create two new nodes, call the nodes Y and N // if the correct response for A is yes... // copy A into Y.text // copy p.text into N.text // else if the correct response is no... // copy A into N.text // copy p.text into Y.text // copy Q into p.text // set Y.yes, N.yes, Y.no, and N.no to null // set p.yes to Y and p.no to N // break from loop // else if p.yes is not null // print p.text as a question // ask for a yes/no reply... //...store in character Yes No // if "yes", set p to p.yes // else if "no", set p to p.no } 3. Run through at least 5 cycles to test the code and to train the program. Be sure to initialize the root node's yes and no references, as well as its animal "guess". Be sure to include matching open and close braces for your loops and if statements. This is a single driver program. The only class that is needed for the driver program to make the binary tree is the BTNode. You will not have to use any other ADT or class definition to make the driver program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a simple Java program based on the provided pseudo code import javautilScanner class BTNode St...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started