In this lab you will implement part of Assignment 9. (If you have already started assignment 9, great; you will have less work to do.)
You should complete at least steps 1-5 during the lab session.
Implement the playOnce method so that it plays the guessing game once, and then returns false. You do not have to implement adding new questions and answers to the decision tree. Run the program and verify that it works for the single question in the initial decision tree. Hint: you can create a BufferedReader to read lines of input from System.in as follows:
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Use the readLine method to read a single line of input (the user's response to a yes/no question). You will probably want to modify the playOnce, run, and main methods so that they throw IOException.
Add code to the saveCurrentDecisionTree method to save the decision tree to a file called "decisiontree.dat". Hint: you can create a PrintStream object that writes to a file as follows:
PrintStream out = new PrintStream(new FileOutputStream("decisiontree.dat"));
Then you can pass this object to the method you created in step 3 to save your decision tree to a file. Don't forget to call close on the PrintStream after you have saved the decision tree. Run the program and verify that it saves your initial three-node decision tree. The file will be in the directory "eclipse-workspace/expertsystem". From a terminal window, run the commands:
cd cd eclipse-workspace cd expertsystem ls cat decisiontree.dat
After running the ls command you should see the file "decisiontree.dat" in the directory listing, and the cat command should print its contents.
Modify the createOrLoadInitialDecisionTree method so that it attempts to read the saved decision tree from the file. If the file cannot be found, then it should create the default initial decision tree instead. Hint: First create a method that takes a BufferedReader as an argument, reads a saved decision tree from the BufferedReader, and returns the root of the decision tree read from the file. Then, you can create a BufferedReader to read from a file as follows:
BufferedReader reader = new BufferedReader(new FileReader("decisiontree.dat"));
You will probably want the method that reads the decision tree to throw IOException. However, createOrLoadInitialDecisionTree should NOT throw IOException. Instead, it should use a try/catch block, where the catch block catches IOException. The try block should attempt to load the saved decision tree, and the catch block should create the default initial decision tree.
You can test step 6 by modifying "decisiontree.dat" in a text editor, and adding extra nodes to the tree. To edit the file, run the following commands from a terminal window:
cd emacs eclipse-workspace/expertsystem/decisiontree.dat &
Don't forget the save the file before re-testing the expert system program.
Download expertsystem.zip from the class web page and import it into your Eclipse workspace.
Demonstrate your expert system to me by deleting "decisiontree.dat", running the expert system program, and then showing me the contents of the newly-created "decisiontree.dat". Extra credit will be given if you can modify this file and load a larger decision tree into the program.
Submit by running the following commands in a terminal window:
cd cd eclipse-workspace submit102 expertsystem