Module 5 - Animal Lab

 Objective

The goal of this assignment is to help you understand the concept of inheritance in Object-Oriented Programming. You will create a simple class hierarchy that demonstrates how inheritance works.

Requirements:

  1. Create a base class called Animal with the following features:

    • A private instance variable name of type String.

    • A constructor that takes a String argument to initialize name.

    • A method makeSound() that prints a generic sound like "Some generic animal sound".

    • A method getName() that returns the name of the animal.

  2. Create a subclass called Dog that inherits from Animal:

    • Override the makeSound() method to print "Woof Woof".

    • Override the toString()

    • Override the hashCode()

    • Override the equals()

  3. Create another subclass called Cat that also inherits from Animal:

    • Override the makeSound() method to print "Meow Meow".

    • Override the toString()

    • Override the hashCode()

    • Override the equals()

  4. In your main method, do the following:

    • Create 2 instances of Dog;

      • Output hash code of each

      • Using the equals method, check to see if the objects are identical

    • Create 2 instances of Cat;

      • Output hash code of each

      • Using the equals method, check to see if the objects are identical

    • Create an ArrayList (create 2 ArrayLists) of Dog and Cat objects and populate with the Dog and Cat objects you created ealier. Loop through the ArrayLists and output each animal's name, and sound using the toString() method.

 Deliverables

Upload the following files in a zip folder that you have created:

  1. Java class files

  2. Screenshot of the Console with the code executing

 

COSC-1437 / ITSE-2457 Computer Science Dept. - Author: Dr. Kevin Roark