20 question Game involving recursive methods

20 question Game involving recursive methods

I have a problem with compiling my program. Any help please.

My code of line where it says "Node first = question.new Node()" i get the error"String.Node cannot be resolved to a type"

import java.util.Scanner;

//import TwentyQuestions.Node;

public class TwentyQuestions { class Node {

    public String question;
    public Node yesChild;
    public String name;
    public Node noChild;
    public void branch() {
        Scanner in = new Scanner(System.in);
        String input;
        if(question != null)            // Keep traversing branches.
        {
            System.out.println(question);   // Ask question.
            input = in.nextLine().trim().toLowerCase();
            if (input.contains("yes"))
                yesChild.branch();      // Yes branch.
            else
                noChild.branch();       // No branch.
        }
        else if(question == null)           // Reached end of branch.
        {
            System.out.println("Is it a/an " + name + "?"); //Guess animal.
            input = in.nextLine().trim().toLowerCase();
            if(input.contains("yes"))   // Animal found. Return to base.
            {
                System.out.println("All your base are belong to us.");
            }
            else                // Guess is incorrect, add new animal.
            {
                System.out.println("I give up.");
                System.out.println("What is your animal?");
                String newName = in.nextLine().trim().toLowerCase();
                System.out.println("What is a question that you "
                        + "would answer no to " + newName + ", but "
                        + "yes to " + name + "?");
                String newQuestion = in.nextLine().trim();
                yesChild = new Node();
                yesChild.name = name;
                noChild = new Node();
                noChild.name = newName;
                name = null;
                question = newQuestion;
                System.out.println("Your animal, " + newName 
                        + ", has been added to my databanks.");
            }
        }
    }
        // TODO Auto-generated method stub

    }   


static String question;
public Node yesChild;
public Node noChild;

public static void main(String[] args) { String root = ""; Scanner in; boolean has; Node first = question.new Node(); // Create first QNode. first.question = "Is your animal larger than a car?"; // Add first question. first.yesChild = new Node(); // Create first Y branch. first.yesChild.name = "Elephant"; // Add 'elephant'. first.noChild = new Node(); // Create first N branch. first.noChild.name = "Mouse"; // Add 'mouse'. do // Loop until 'quit' is entered. { first.branch(); System.out.println("Play again or quit?"); in = new Scanner(System.in); has = in.nextLine().trim().toLowerCase().contains("quit"); } while(!(has)); System.out.println("Thanks for playing, have a nice day."); }

/*public void branch() {

}*/

}

View Answers









Related Tutorials/Questions & Answers:
20 question Game involving recursive methods
20 question Game involving recursive methods  I have a problem...; public class TwentyQuestions { class Node { public String question...); String input; if(question != null) // Keep traversing branches
Game
Game  How to develop a game using java? give me a total code for any simple game
Advertisements
recursive method
recursive method  Write a recursive method to add the first n terms of the series 1 + (1/2) - (1/3) + (1/4) - (1/5
game
game  How to make 3D game in java Applet
Game
Game  how can create simple game in java . thank u so match ,please help
game
game  Hi thank you for answers.I am devoloping a java game caled Duck Hunt Game in netbeans6.7.1 software and I need help in some codes...,if you have this game's code please post me as soon as possible
Fibonacci (Recursive)
Fibonacci (Recursive)  I need to write a program for my AP CS class... to do: Assignment: 1.Write a recursive method that takes in a single integer (x.... Instructions: Use these sample run output values: Recursive Fibonacci: 0, 3, 11
methods
methods  PrintStream class has two formatting methods,what
methods
methods  PrintStream class has two formatting methods,what
methods
methods  PrintStream class has two formatting methods,what
ModuleNotFoundError: No module named 'recursive'
ModuleNotFoundError: No module named 'recursive'  Hi, My Python... 'recursive' How to remove the ModuleNotFoundError: No module named 'recursive' error? Thanks   Hi, In your python environment you
recursive - Java Beginners
recursive   Question Details: I need to write a recursive method that displays the lyrics of the song "Bingo". Verse 1: There was a farmer..., Clap, Clap, Clap, Clap) - Write a Java program to test your recursive
recursive fuction in java
recursive fuction in java  A class has a recursive method which return a boolean value. If a codition is fail & control goes to out of loop... method which call that recursive method
Question?
Question?  My question is how to: Add a menu bar to the program... " + PICKS + " numbers"); Font serifBold = new Font("Serif", Font.BOLD, 20..., 50000, 1000000}; public JLottery2() { super("Lottery Game
Recursive regex PHP - PHP
Recursive regex PHP  any one? that can send me the code of regular expression that checks other regular expression for its correctness.   Hi, Please check at http://www.roseindia.net/tutorial/php/phpbasics/PHP
ModuleNotFoundError: No module named 'djangorestframework-recursive'
ModuleNotFoundError: No module named 'djangorestframework-recursive'  ...: No module named 'djangorestframework-recursive' How to remove the ModuleNotFoundError: No module named 'djangorestframework-recursive' error
ModuleNotFoundError: No module named 'djangorestframework-recursive'
ModuleNotFoundError: No module named 'djangorestframework-recursive'  ...: No module named 'djangorestframework-recursive' How to remove the ModuleNotFoundError: No module named 'djangorestframework-recursive' error
ModuleNotFoundError: No module named 'recursive-aronr'
ModuleNotFoundError: No module named 'recursive-aronr'  Hi, My... named 'recursive-aronr' How to remove the ModuleNotFoundError: No module named 'recursive-aronr' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'recursive-compression'
ModuleNotFoundError: No module named 'recursive-compression'  Hi...: No module named 'recursive-compression' How to remove the ModuleNotFoundError: No module named 'recursive-compression' error? Thanks   Hi
ModuleNotFoundError: No module named 'recursive_dict'
ModuleNotFoundError: No module named 'recursive_dict'  Hi, My... named 'recursive_dict' How to remove the ModuleNotFoundError: No module named 'recursive_dict' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'recursive-itertools'
ModuleNotFoundError: No module named 'recursive-itertools'  Hi, My... named 'recursive-itertools' How to remove the ModuleNotFoundError: No module named 'recursive-itertools' error? Thanks   Hi
ModuleNotFoundError: No module named 'recursive_listfunction'
ModuleNotFoundError: No module named 'recursive_listfunction'  Hi...: No module named 'recursive_listfunction' How to remove the ModuleNotFoundError: No module named 'recursive_listfunction' error? Thanks   Hi
ModuleNotFoundError: No module named 'recursive_package'
ModuleNotFoundError: No module named 'recursive_package'  Hi, My... named 'recursive_package' How to remove the ModuleNotFoundError: No module named 'recursive_package' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'recursive-parse'
ModuleNotFoundError: No module named 'recursive-parse'  Hi, My... named 'recursive-parse' How to remove the ModuleNotFoundError: No module named 'recursive-parse' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'recursive-sgd'
ModuleNotFoundError: No module named 'recursive-sgd'  Hi, My... 'recursive-sgd' How to remove the ModuleNotFoundError: No module named 'recursive-sgd' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'sympy_recursive'
ModuleNotFoundError: No module named 'sympy_recursive'  Hi, My... named 'sympy_recursive' How to remove the ModuleNotFoundError: No module named 'sympy_recursive' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'djangorestframework-recursive'
ModuleNotFoundError: No module named 'djangorestframework-recursive'  ...: No module named 'djangorestframework-recursive' How to remove the ModuleNotFoundError: No module named 'djangorestframework-recursive' error
ModuleNotFoundError: No module named 'recursive-abc'
ModuleNotFoundError: No module named 'recursive-abc'  Hi, My... 'recursive-abc' How to remove the ModuleNotFoundError: No module named 'recursive-abc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'recursive-decorator'
ModuleNotFoundError: No module named 'recursive-decorator'  Hi, My... named 'recursive-decorator' How to remove the ModuleNotFoundError: No module named 'recursive-decorator' error? Thanks   Hi
ModuleNotFoundError: No module named 'recursive-diff'
ModuleNotFoundError: No module named 'recursive-diff'  Hi, My... named 'recursive-diff' How to remove the ModuleNotFoundError: No module named 'recursive-diff' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'recursive_print'
ModuleNotFoundError: No module named 'recursive_print'  Hi, My... named 'recursive_print' How to remove the ModuleNotFoundError: No module named 'recursive_print' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'recursive-yaml'
ModuleNotFoundError: No module named 'recursive-yaml'  Hi, My... named 'recursive-yaml' How to remove the ModuleNotFoundError: No module named 'recursive-yaml' error? Thanks   Hi, In your python
java program on recursive method
java program on recursive method  in how many ways can you make change for one dollar(100 cents) using pennies(1-cent coins), nickels(5 cents), dimes(10 cents),and quarter(25 cents)? the coins must add up to the exact total
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question
Question   When there is an exception in my program how java runtime system handles
javascript recursive - Java Beginners
javascript recursive   Hi,Sir I have a problem with javascript recursive function This function is used to read dynamically read xml node names... PT001 Food PG001 Cake My recursive function
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Gud morning sir, I have asked u some question regarding...;td><input type="text" size="20" name="name"></td></tr> <tr><td>Registration:</td><td><input type="text" size="20
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
Methods of HttpServlet
Methods of HttpServlet  What are methods of HttpServlet
question
JTextField text=new JTextField(20); JButton b=new JButton("Search
java game
java game  Can anyone please give me a game source code
ModuleNotFoundError: No module named 'colcon-recursive-crawl'
ModuleNotFoundError: No module named 'colcon-recursive-crawl'  Hi...: No module named 'colcon-recursive-crawl' How to remove the ModuleNotFoundError: No module named 'colcon-recursive-crawl' error? Thanks   Hi
ModuleNotFoundError: No module named 'recursive_print_list'
ModuleNotFoundError: No module named 'recursive_print_list'  Hi...: No module named 'recursive_print_list' How to remove the ModuleNotFoundError: No module named 'recursive_print_list' error? Thanks   Hi
ModuleNotFoundError: No module named 'colcon-recursive-crawl'
ModuleNotFoundError: No module named 'colcon-recursive-crawl'  Hi...: No module named 'colcon-recursive-crawl' How to remove the ModuleNotFoundError: No module named 'colcon-recursive-crawl' error? Thanks   Hi
ModuleNotFoundError: No module named 'recursive-dictionary-update'
ModuleNotFoundError: No module named 'recursive-dictionary-update'  ...: No module named 'recursive-dictionary-update' How to remove the ModuleNotFoundError: No module named 'recursive-dictionary-update' error? Thanks
ModuleNotFoundError: No module named 'recursive-monkey-patch'
ModuleNotFoundError: No module named 'recursive-monkey-patch'  Hi...: No module named 'recursive-monkey-patch' How to remove the ModuleNotFoundError: No module named 'recursive-monkey-patch' error? Thanks   Hi
ModuleNotFoundError: No module named 'colcon-recursive-crawl'
ModuleNotFoundError: No module named 'colcon-recursive-crawl'  Hi...: No module named 'colcon-recursive-crawl' How to remove the ModuleNotFoundError: No module named 'colcon-recursive-crawl' error? Thanks   Hi
ModuleNotFoundError: No module named 'dict-recursive-update'
ModuleNotFoundError: No module named 'dict-recursive-update'  Hi...: No module named 'dict-recursive-update' How to remove the ModuleNotFoundError: No module named 'dict-recursive-update' error? Thanks   Hi

Ads