

/**
 * VegDB.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 VegDB {
   public static Visitor builder = new PlayVisitor();
   public static void main (String[] args) throws java.io.IOException {


      BTree vegDB;

      // build the initial tree
      String ques = "Is it green?";
      String no = "Carrot";
      String yes = "Spinach";

      BTree y = new BTree(yes, null, null);
      BTree n = new BTree(no, null,null);
      vegDB = new BTree(ques,n,y);

      // build the tree
      while (true) {
      String veg = (String)vegDB.acceptVisitor(builder, null);
      System.out.println(veg);

      int n1 = JOptionPane.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("VegDataBase");
      ObjectOutputStream out = new ObjectOutputStream(fout);
      out.writeObject(vegDB);
      out.close();
      System.exit(0);
   }
   
}// AnimalDBBuilder
