Lab 3: Inheritance at the Zoo!
Due Date and Submission Requirements
- Due Date: Thursday, September 12th at 11:59 p.m.
- Partner Information: This is an individual assignment. You are allowed to collaborate with other students, but each student must submit their individual, independent solution.
- Submission Instructions: Upload your solutions (.java file), entitled Animal.java, Amphibian.java, Lion.java, and Bird.java to the BrightSpace(D2L) Lab 3 Dropbox.
The goal of this lab is:
- Gain experience using Java inheritance
Background and Directions
You've been tasked with writing Java classes that keep track of animal information at the new Bozeman Zoo (coming soon... hopefully).
Using ZooDemo.Java, you will fill in the missing classes/methods to get the desired output seen below. You are NOT allowed to modify ZooDemo.java. There are three types of animals you need to keep track of
A Amphibian.java class. An Amphibian has the following information:
- The species
- Weight
- The continent where the species is most commonly found
- Population (how many of that species are still alive)
- The diet of the amphibian
A Lion.java class. A lion has the following information:
- The species
- Weight
- The continent where the species is most commonly found
- Population (how many of that species are still alive)
- The pack size (ie how many lion are part of a typical pack)
A Bird.java class. A bird has the following information:
- The species
- Weight
- The continent where the species is most commonly found
- Population (how many of that species are still alive)
- The wingspan of the bird
All three of these classes must inherit from an Animal class, which holds information about a basic animal. You must determine which instance fields/methods go inside of the Animal class (if you get stuck here, look back on our Food example from class ).
You must define the following methods: getSpecies(), getWeight(), getContinent(), getDiet(), getWingSpan(), and getPackSize(). You must figure out which class these methods go in (remember you are using inheritance)!!.
You must also define the checkPopulation() method. Before returning this.population, this method should check to see if that animal species is endangered or not. An animal species is considered endangered of the remaining population of that animal is less than or equal to 2500. If the population is less than or equal to 2500, then this method should print out "This animal is endangered!".
Lastly, each type of animal has a makeSound() method. While the method name is the exact same, the output of this function changes from class to class. For the amphibian, this method should print out "The [species-name] goes Blub Blub!". For the lion, if should print out "The [species-name] goes Roarrr!". For the bird, it should print out "The [species-name] goes chirp chirp chirp!".
You do not need to use interfaces for this assignment.
Rules
You are NOT allowed to modify ZooDemo.java. If you modify ZooDemo.java in any way (other than changing the package statement line), the you will lose significant points!
Starting Code
Required Output
When your program is run, your output should look exactly the same as seen in this screenshot.
Grading (10 points)
- 3 points - Amphibian.java, Lion.java, and Bird.java are correctly defined
- 1 points - Animal.java is correctly defined
- 2 point - Inheritance is used correctly
- 1 points- getSpecies(), getWeight(), getContinent(), getDiet(), getWingSpan(), and getPackSize() are correct
- 1 points - makeSound() is correct defined
- 1 point- checkPopulation() is correct defined
- 1 point- Your program matches the output exactly
Deductions
-5 points if inheritance is not used