I just finished this guessing game and I have completed the first part
(answerIsCorrect = ask("Is it a Kiwi? ", keyboard);
and compiled it with no errors and works. Then I did the same with the bottom and it doesnt work. What have I done wrong?
public class animalquiz { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); boolean answerIsCorrect; System.out.println("Think of an animal.\n"); if(ask("Is it a bird? ", keyboard)) { if(ask("Is it native to Australia? ", keyboard)) { answerIsCorrect = ask("Is it a kookaburra? ", keyboard); } else { if(ask("Is it a Colourful? ", keyboard)) { answerIsCorrect = ask("Is it a Parrot? ", keyboard); } else { if(ask("Does it fly? ", keyboard)) { answerIsCorrect = ask("Is it a Crow? ", keyboard); } else { if(ask("Does it live in a cold place? ", keyboard)) { answerIsCorrect = ask("Is it a Penguin? ", keyboard); } else { answerIsCorrect = ask("Is it a Kiwi? ", keyboard); } } } } } else { { if(ask("Does it live in the ocean? ", keyboard)) { answerIsCorrect = ask("Is it a fish? ", keyboard); } else { if(ask("Is it Cold blooded? ", keyboard)) { answerIsCorrect = ask("Is it a Snake? ", keyboard); } else { if(ask("Does it have a pouch? ", keyboard)) { answerIsCorrect = ask("Is it a Kangaroo? ", keyboard); } else { if(ask("Is it Domestic? ", keyboard)) { answerIsCorrect = ask("Is it a Dog? ", keyboard); } } } } } } if(answerIsCorrect) { System.out.println("Yes! I am invincible!"); } else { System.out.println("Oh. Well, thank you for playing."); } } } /** * A utility method to ask a yes/no question * * @param question the question to ask * @param a scanner for user input * * @return whether the user answered "yes" (actually, whether the user answered anything starting with Y or y) */ private static boolean ask(String question, Scanner keyboard) { System.out.print(question); String answer = keyboard.nextLine().trim(); return answer.charAt(0) == 'Y' || answer.charAt(0) == 'y'; } }