

/**
 * GuesserSimpleLoadSave.java
 *
 *
 * Created: Tue Oct 15 21:40:28 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */
import java.util.*;
import java.io.*;
import javax.swing.*;

public class GuesserSimpleLoadSave {
   public static Visitor player = new PlayVisitor();
   public static void main (String[] args) throws java.io.IOException {

      BTree animalDB = new BTree();
      //load tree from a database
      try {
	 FileInputStream fin = new FileInputStream("ZooDatabase");
	 ObjectInputStream in = new ObjectInputStream(fin);
	 animalDB = (BTree)in.readObject();
	 in.close();
      }
      catch(Exception exc){
	 System.out.println(exc);
      }
      
      //playing guessing game
      while (true) {
      String animal = (String)animalDB.acceptVisitor(player, null);
      System.out.println(animal);
      int n1 = JOptionPane.showConfirmDialog(null,
						"Want to continue playing",
						null,
					       JOptionPane.YES_NO_OPTION);
      if ( n1 == JOptionPane.NO_OPTION) 
	    break;
      }
       
      // store the knowledge gathered in a file using object serialization
      FileOutputStream fout = new FileOutputStream("ZooDataBase");
      ObjectOutputStream out = new ObjectOutputStream(fout);
      out.writeObject(animalDB);
      out.close();
      System.exit(0);
   }
   
}// GuesserSimpleLoadSave
