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() {
}*/
}