

/**
 * AnimalDBBuilder.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 java.awt.*;
import javax.swing.*;

public class AnimalDBBuilder {
   public static Visitor builder = new PlayVisitor();
   public static void main (String[] args) throws java.io.IOException {


      BTree animalDB;

      // build the initial tree
      String ques = "Is it a mammal?";
      String yes = "Cow";
      String no = "Parrot";

      BTree y = new BTree(yes, null, null);
      BTree n = new BTree(no, null,null);
      animalDB = new BTree(ques,n,y);

      // build the tree
      while (true) {
      String animal = (String)animalDB.acceptVisitor(builder, null);
      System.out.println(animal);
      JOptionPane jp = new JOptionPane();
      jp.setFont(new Font("TimesRoman", Font.BOLD, 20));
      int n1 = jp.showConfirmDialog(null,
						"Want to continue building",
						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);
   }
   
}// AnimalDBBuilder
