The link tied to this post is what I have to do. I could do this if I all the answers and questions were already established. My problem is that I don't know how to make the program start from scratch and make it "learn". This is my code as of right now:

    import java.util.*;
    public class assignment8{
      static treeNode root = new treeNode("Does it have legs?", null, null);
      public static void main(String[] args){
        root.left = new treeNode("Is it a cat?", null, null);
        root.right = new treeNode("Is it a snake?", null, null);
        guess();
      }
      static void guess(){
        Scanner scan = null;
        try{
          scan = new Scanner(System.in);
        }
        catch (Exception e){
          System.out.println(e);
        }
        System.out.println(root.data);
        String ques = scan.next();
        if(ques.equals("yes")){
          root = root.left;
          System.out.println(root.data);
          String ques2 = scan.next();
          if(ques2.equals("yes")){
            System.out.println("I win! Continue?");
          }else if(ques2.equals("no")){
            System.out.println("I give up. What is it?");
            String ans = scan.next();
            System.out.println("Please type a question that is yes for " + ans + " and no for cat");
            String newQues = scan.next();
            root.right = new treeNode(newQues, null, null);
            System.out.println("Continue? yes/no");
            String cont =  scan.next();
            if(cont.equals("yes")){
              guess();
            }
          }
        }else if(ques.equals("no")){
          root = root.right;
          System.out.println(root.data);
        }
      }
    }
    class treeNode{
      String data;
      treeNode left;
      treeNode right;

      treeNode(String newdata, treeNode left, treeNode right){
        this.data = newdata;
        this.left = left;
        this.right = right;
      }
    }

I realize that it's all over the place. To be honest I'm quite stuck as to how to make the program "learn" as more people play it. Any help would be appreciated. I know that this is a lot to read and I apologize. Thanks in advance to any that help.

I'm not sure what the real question is here, so here's an answer that may or may not hit the target, but at least it may help clarify the question.
As the user enters new questions you add them to your Tree structure(s). At the end of each run you write all that data to a file, ready to read in at the start of the next run. You can use an ObjectOutputStream to write the whole tree structure in simgle method call.

How would I do that? I'm a beginning programmer so I apoplogize if my questions are a bit...well, stupid.

"How would I do that?" is a very big question! Try taking it one small step at a time see how it goes.

ps: There are lots of beginners here, so don't worry about asking about simple things. The only "stupid" questions are ones so vague or incomplete that nobody knows to to start answering them.

I should have been more specific. I meant how would I do the ObjectOutputStream part. That's my bad. Also, I probably should have mentioned this in my last post but we haven't gone over ObjectOutputStream so I don't think I can use that. Any other suggestions?

e you can just print your data to an ordinary text file, then re-construct your data when you read the text back in. Google is your friend, closely followed bythe Oracle Java tutorials and the Java API documentation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.