Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners 20 question Game involving recursive methods

Have Programming Question? Ask it here!
 
 
 


Rashad Morris
20 question Game involving recursive methods
0 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


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() {

}*/

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
20 question Game involving recursive methods
20 question Game involving recursive methods  I have a problem... TwentyQuestions { class Node { public String question; public Node...; 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
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
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
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
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
java game
java game  Can anyone please give me a game source code
game programming
game programming  Hi. i have witten the script and have almost completed developing a social game like mafia wars. can any one plz help me by answering me some of my doubts.. after uploading the game on facebook how tokeep data
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
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
JAVA Game
JAVA Game  I want to make a JAVA game...in dat game...d player has to input a word in 10 secnds...4 dat m running a delay loop... but the problem is not...i am not getting any way...to make that input field(eg: String str
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
top 20 basic programm of java
top 20 basic programm of java  what is the top 20 rule to learn the basic of java.   Learn Java through the following links: http://www.roseindia.net/java/ http://www.roseindia.net/java/beginners/index.shtml
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
game Nim - Java Beginners
game Nim  how is the search tree for a game Nim looks like
Algorithms: Recursive Binary Search
20 21 22 23 24 25 26 27 28 /** Recursive binary search... Java Notes: Algorithms: Recursive Binary Search Recursive Binary Search... recursive method calls instead of loops. However the iterative version
Blackjack game - IDE Questions
Blackjack game  Create a java code for a simple blackjack game for just one hand of Blackjack, it does not need to include money and betting
all combination via recursive function
all combination via recursive function  hello i have a php scrpt which generates all possibilities fro a given string recursive function is used in it. i have given its code below $charset = "abcd"; $charset_length
tetris game code - Swing AWT
tetris game code  To develop a JAVA puzzle game which is a "variation" of the Tetris game
Create a Swamp Game in Java
Create a Swamp Game in Java  You are to create a game called ‚??Get Out of My Swamp‚??. In this game an ogre, called ‚??Hek‚??, wanders around his... two ogre enemies in the same place they kill the ogre and the game ends. Full
Java Game Pontoon
Java Game Pontoon  Could someone help me create a programme for the game pontoon //play a game of pontoon import java.util.*; public class Pontoon { public static void main (String args[]) { //deal initial hands
PHP Array Merge Recursive
PHP Array Merge Recursive The PHP array_merge_recursive() function is same..._recursive() is that if two or more than two elements have the same key... of array_merge_recursive() is:  General Format array array
Create a guessing game - Framework
Create a guessing game  Create a guessing game that picks a random number between 1 and 100 and lets you keep guessing until you get it right! You have two decisions to make. The first one tells you whether your guess was TOO
Java game Pontoon
Java game Pontoon  Hello. I have trouble with my pontoon code. I ahve done it using simple java programming. It is working BUT it dosent stops when the players hand rises ober 24 points. where in game the player should be bust
Java program for connectfour game
connectFour game. I need help with resolving the logic for this problem. I appreciate...; ConnectFourServer game = new ConnectFourServer(); private ConnectFourClient..., player, turn, num, full; boolean filled; /* The game board is a grid
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
How do i slow down the game (othello game)??
How do i slow down the game (othello game)??  Hello, I built an othello game that can be played by 2 humans , human and computer and two computers... with each other the fram doesn't appear until the game is finish. I think it is becase
20 Futuristic Technologies that are going to Change the World
in the time to come that are already in the making. Here we would introduce 20 futuristic... is the next leap we can expect. 20   Space elevator
Can anyone assist with the coding of this game?
Can anyone assist with the coding of this game?  I am in need of the coding for this game. I need to write a "Hangman" game that will randomly generate a word from a text file and will prompt the user to guess one letter
game programming code - Swing AWT
game programming code  write a snake program using swings with step by step explanation?. please send me this source code to my mail id with step by step explanation
Two user chess game - Applet
Two user chess game  Write a program for a two user chess game(Users must be on different systems)? please send me this source code to my mail id with step by step explanation
PHP Array Replace Recursive
PHP Array Replace Recursive: PHP provides array_replace_recursive() function..._replace_recursive() replaces the values of first array with the same values from...() is:  General Format array array_replace_recursive(array
How ro convert char into string using recursive function in c#??
How ro convert char into string using recursive function in c#??  This coding is for java...but i want this in c# How ro convert char into string using recursive function in c#?? char [] ch={'H','E','L','L','o'}; TO ans
question
question  Gud morning sir, I have asked u some question regarding...="text" size="20" name="name"></td></tr> <tr><td>Registration:</td><td><input type="text" size="20" name="reg"><
Craps Game Java Programming Help
Craps Game Java Programming Help  Craps is a casino game that involves the throwing of a pair of dice. Based on the throw, the thrower either gets to continue throw (and win money), or stops throwing (and loses money). Write your
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
Methods of HttpServlet
Methods of HttpServlet  What are methods of HttpServlet
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
programes on methods
programes on methods   write a program to implement bubble sort write a program to demonstrate call by value and call by reference.(pass objects as parameters) write a program to calculate factorial of a no. using recursive
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
BRICK-BREAKER game concept - Java Beginners
BRICK-BREAKER game concept  I am planning to write a program for BRICK-BREAKER GAME. can any 1 help me any 1 can u plz help me frzzz?? you can also send the mails to poramboku.me@gmai.com
Java game bulls and cows
Java game bulls and cows In this tutorial, you will learn how to implement bulls and cows game in java. The game bulls and cows is an ancient game...;quit", the user will come out from the game. If the user inputs 4 digit
How to design a little game
How to design a little game In this example we are going to design a little game which is used by the children easily. New File: Take a new file with appropriate size. Rounded Rectangle Tool: Choose Rounded Rectangular
 

 

 

DMCA.com