Results 1 to 2 of 2
  1. #1
    oswilf is offline Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Post 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. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,548
    Rep Power
    23

    Default

    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.

Similar Threads

  1. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  2. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 04:17 PM
  3. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  4. AnimalGame dilema
    By geork in forum New To Java
    Replies: 2
    Last Post: 02-17-2008, 09:26 AM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

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