1. Member
Join Date
Sep 2010
Posts
1
Rep Power
0

## AnimalGame program

CAN SOMEONE HELP ME OUT???? IM TRYING TO WRITE MY FIRST PROGRAM BUT IM STUCK.
THIS IS THE PROBLEM:
PROGRAM KNOWS ONLY 3 THINGS, DOGS HAS 4 LEGS , CHICKEN HAS 2 AND FISH HAS 0
USER FIRST SPECIFIES WHAT KIND OF ANIMAL HE'S PLAYING WITH
THEN HE TRIES TO GUESS HOW MANY LEGS THAT ANIMAL HAS
PROGRAM STARTS BY PROMPTING USER WITH CHOOSE ANIMAL
AND ENTER AN ANIMAL
IF ANIMAL IS NONE OF 3 KNOWN ALREADY PRINT: I DON'T KNOW ANIMAL. WANNA TRY AGAIN?(Y/N). IF YES PROGRAM PROMPT ANIMAL CHOICE AGAIN BUT IF NO PROGRAM TERMINATES

WHEN ANIMAL IS KNOWN OF 3 MENTIONED EARLIER, PROGRAM ASKS: HOW MANY LEGS DOES IT HAVE?
THEN PRINT: WON (IF GUESS IS CORRECT) AND LOST (IF GUESS ISN'T)
EITHER WAY PROGRAM TERMINATES

SO FAR.... THIS IS WHAT I GOT
import java.util.Scanner;

public class AnimalGame
{
public static final int DOG = 4; // # legs
public static final int CHICKEN = 2; // # legs
public static final int FISH = 0; // # legs

public static void main( String[] args)
{

String animalSelected;
Scanner scan = new Scanner (System.in);

System.out.println("Choose an animal:");
animalSelected = scan.nextLine();

if
{
System.out.println("How many legs does "+ animalSelected + "have?");
int numberOfLegs= scan.nextInt();

if((numberOfLegs==DOG)|| (numberOfLegs==CHICKEN)|| (numberOfLegs==FISH));
{
System.out.println("You win!");
}
else
{
System.out.println("You lose!");
}
}

else
System.out.println("I don't know that animal. Do you want to try again (y/n)");
}
}

2. Can you show the console from when you execute the program and explain what the problem is with how the program works.

PROGRAM TERMINATES
What is to keep the program from ending? You need a loop of some kind to keep the code executing.

And PLEASE do NOT use all caps.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•