Question: Revise the animal-guessing program from Figure 9.8 so that the initial knowledge tree is obtained by reading information from a file. Also, when the program

Revise the animal-guessing program from Figure 9.8 so that the initial knowledge tree is obtained by reading information from a file. Also, when the program ends, the knowledge tree at that point is written to the same file. You must carefully specify the format of the data in this file. The format should make it easy to do two things: (a) read the file and set the initial tree, and (b) write the knowledge tree to the file, using some kind of traversal.

FIGURE 9.8 The Animal-Guessing Program Java Application Program // FILE: Animal.java // This animal-guessing program illustrates the use of the binary tree node class. import edu.colorado.nodes.BTNode; // For BTNode import java.util.Scanner; public class Animal private static Scanner stdin = new Scanner(System.in); public static void main(String[ ] args) { BTNode root;

FIGURE 9.8 The Animal-Guessing Program Java Application Program // FILE: Animal.java //

FIGURE 9.8 The Animal-Guessing Program Java Application Program // FILE: Animal.java // This animal-guessing program illustrates the use of the binary tree node class. import edu.colorado.nodes.BTNode; // For BTNode import java.util.Scanner; public class Animal private static Scanner stdin = new Scanner(System.in); public static void main(String[ ] args) { BTNode root; instruct( ); root = beginningTree( ); do play(root); while (query("Shall we play again?")); System.out.println("Thanks for teaching me a thing or two."); public static void instruct(O | The implementation of this method is omitted-write it yourself! public static void learn(BTNode current) I| The implementation of this method is Self-Test Exercise 9. public static void play(BTNode current) { while (!current.isLeaf( )) { if (query(current.getData( ))) current = current.getLeft(); else current = current.getRight(); } System.out.print ("My guess is " + current.getData( ) + ". "); if (!query("Am I right?")) learn(current); else System.out.printin("I knew it all along!");

Step by Step Solution

3.49 Rating (189 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To revise the animalguessing program from Figure 98 to read and write the knowledge tree fromto a fi... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Data Structures and Other Objects Using Java Questions!