So far, you have learned about design and how to create a simple Java application using an IDE. Now, you are going to gain some experience writing an object-oriented program with classes, objects, inheritance, and polymorphism. These terms sound complex, but you will find they are not difficult to use. You will be drawing on all the information you have gained, and this project will require some time, so start early, and pay attention to instructions.
For this project, you will create a Java program that allows the user to select a category of animal from a menu and then a specific animal in that category, then view information about their selection. To facilitate this, we will use a class and inheritance structure as follows:
Program/Main Class: AnimalInfo. This file is for the code (in the method “Main()”) that will run the program, present the list, prompt for input, execute the appropriate class method, and then terminate. Note that this file may not include any information about the categories of animals or any specifics about animals. That information comes from the inheriting classes discussed below.
- Create a project called “AnimalInfo”.
- Using the method “Main()”, present the user with three animals and ask them to select one to learn more about that animal. The animals in the menu must match your “inheriting classes” discussed below.
- When the user selects an animal from the menu, execute the “displayInfo()” method from the appropriate inheriting class.
- Use code comments to annotate your source code, indicating what each line of code does as well as how it works.
Parent Class: (Name to be determined.) This file is for the broad category of animals that the user can examine in your program, such as dogs, horses or fish. Your program may contain only one parent class (users will only be able to select from a single category of animals).
- Create a class file, naming it according to the category of animals that you’ve decided to use.
- Do NOT inherit another file/class. (Do not use the “extends” keyword in the class declaration.)
- Create a method in your class file called “displayInfo()”.
- This displayInfo() method will only be executed if inheritance fails, so in displayInfo(), write code that reports to the screen that this parent class has been engaged by mistake. For example, if executed this method will generate user-friendly text on the screen such as: “Incorrect class inheritance, please contact technical support.”
- Use code comments to annotate your source code, indicating what each line of code does as well as how it works.
Inheriting Classes: (Names to be determined.) Create three class code files that inherit from the parent class discussed above. For example, if you named your parent class “Dogs”, then your inheriting class files might be “Bulldog”, “Beagle” and “Poodle”. (You may not use those examples for your program.)
- Create three class files, reflecting the animals listed in the menu that was presented to the user.
- Within each of these class files, declare the class so that it inherits your parent class (using the “extends” keyword).
- In each class, create a method called “displayInfo()” so that it will override the same method in the parent class. (This will cause text about the selected animal to appear on the screen instead of the error report you wrote for the same method in the parent class.)
- The text must be a short description of the animal, such as where they live and/or their physical parameters and something interesting about them (1 paragraph of no more than 3-4 sentences). (You do not need to cite your source for this information.)
- Use code comments to annotate your source code, indicating what each line of code does as well as how it works.
Create a ZIP file that includes your project folder and Word document and upload it to the course portal.