
/**
 * PlayVisitor.java
 *
 *
 * Created: Fri Oct 25 18:40:58 2002
 *
 * @author <a href="mailto: "</a>
 * @version
 */
import javax.swing.JOptionPane;

public class PlayVisitor implements Visitor{
   public static Visitor learner = new LearnVisitor();
   public PlayVisitor (){
      
   }
   public Object operation(Object host, Object inp) throws java.io.IOException
   {
      BTree bt = (BTree) host;
      if ( bt.isLeaf()){
	 int n1 = JOptionPane.showConfirmDialog(null," Is it "
						+bt.getData()+"?",null,
					       JOptionPane.YES_NO_OPTION);
	 if ( n1 == JOptionPane.NO_OPTION) {
	    return (bt.acceptVisitor(learner, null));}
	 else {
	    return bt.getData();
	 } // end of else
      }
      //internal node
      int n2 = JOptionPane.showConfirmDialog(null,bt.getData(),null,
					       JOptionPane.YES_NO_OPTION);
      if ( n2 == JOptionPane.NO_OPTION)
	 return (bt.getLeft().acceptVisitor(this, null));
      else 
	 return (bt.getRight().acceptVisitor(this, null));
      
   }     
}// PlayVisitor
