Project #1 CMSC 131
Due Monday 9/19/05, 11:00 pm Object-Oriented Programming I
Type of project: Open Fall 2005

Objective

This project will allow you to practice variables, strings, input/output facilities, conditionals, loops, and the Eclipse IDE.

Overview

You will write a very (very) simple game, in which the user will select an animal and then guess how many legs that animal should have.  (It is not a very challenging or interesting game, is it?)

This project is considered "open". Please visit the course web page for information regarding the open/closed policy for projects of this course.

Specifications

Your program knows three things:  A dog has 4 legs, a chicken has 2 legs, and a fish has 0 legs.  That's it.

The program execution consists of two phases:

  1. The user specifies what kind of animal he/she is playing with.
  2. The user tries to guess how many legs that animal has.

The program begins by prompting the user with:

    Choose an animal:

The user then enters the name of an animal.  At this point one of two things could occur:  Either the animal selected is one of the three animals that the program knows about, or the user has selected an animal that is not on this list.

When the Animal Selected is NOT One of the Three Known Animals

If the animal is not one of the three animals that the program knows about, the program will print:

        I don't know that animal.  Do you want to try again? (y/n)

If the user answers "y", then the program will again ask for the user to enter an animal, and continue from there.  If the user answers "n", then the program should terminate with no further output.

When the Animal Selected is One of the Three Known Animals

The program then asks the user:

    How many legs does a <AnimalSelected> have?

(In the line above, <AnimalSelected> represents the animal chosen by the user:  either "dog", "chicken", or "fish".)

 The user now enters his/her choice, and the program will check whether or not the guess is correct.  If the user guesses correctly, the program will print out:

    You win!

But if the user guesses incorrectly, then the program will print out:

    You lose!

Either way, the program terminates after reporting whether or not the user wins or loses.

Getting Started

In order to help you get started, we have defined a AnimalGame class with a main( ) method in a file named AnimalGame.java. This file can be retrieved by checking out the project from the CVS repository. Remember that you must have set up your repository in order to check out and submit projects.  Information on how to do this can be found in the Managing Homeworks section of the Eclipse tutorial. Follow the instructions given there to check out project p1. Then when you switch back to the Java perspective, you will see the above files, and you will be able to start modifying them.

Requirements

Sample Run

The following provides a sample run of the program you are expected to write. Keep in mind this is just an example and not the only scenario your program is expected to handle. 

    Choose an animal: frog
    I don't know that animal. Do you want to try again? (y/n) y
    Choose an animal: chicken
    How many legs does a chicken have? 100
    You lose!

(Note that the portions above in italics represent the input entered by the user.)

Submission

Submit your project using the submit project option associated with Eclipse.  After you have submitted your project, you should visit the submit server.  There you can obtain limited feedback about how well your project is performing.

Challenge Problem

Modify your program so that it does not use any occurrences of the logical connectives && and ||.  Please read the information on the syllabus about "challenge problems".  You will not receive a higher grade by implementing them.

Web Accessibility