Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java In the second inheritance hierarchy, we will be creating animals that consists of a smaller hierarchy than the previous problem. These classes include an
java
In the second inheritance hierarchy, we will be creating animals that consists of a smaller hierarchy than the previous problem. These classes include an Animal, Dog, and Cat. The Dog and Cat classes are both children of the Animal class. This problem will help us practice our inheritance and polymorphism principles. The following are the requirements for each class. a. 1. Class Animal: Create a class named Animal that has the following instance properties and public interface. a. Instance Properties: i. int age - the age of the animal. ii. String size - the size of the animal. b. Public Interface: i. Constructors: Two constructors need to be provided. Namely a default constructor and a workhorse constructor. The default constructor will initialize the instance properties to their default values (numbers to 0 and Strings to ""). ii. Getters and Setters for each instance property. iii. public boolean equals(Object o) - The method returns true if the two Animals have the same age and size and false, otherwise. iv. public String toString0 The method returns a String representing the Animal object that includes the age and size. The formatted string should follow this example: I am an unknown medium animal that is 9 years old.. v. public String speak() This method returns a String representing an unknown Animal. Specifically, it returns the String "Unintelligible sound. 2. Class Dog: Create a class named Dog that is a child of Animal and has the following instance properties and public interface. Instance Properties: i. String breed the breed of the dog. b. Public Interface: i. Constructors: Two constructors need to be provided. Namely a default constructor and a workhorse constructor. The default constructor will initialize the instance properties to their default values (numbers to 0 and Strings to "*"). Note, you must utilize the super() constructor call appropriately to set the parent's instance properties. ii. Getters and Setters for each instance property. iii. public boolean equals(Object o) - The method returns true if the two Dogs have the same age, size, and breed and false, otherwise. Do not forget to use the parent's equals() method when applicable. iv. public String toString() - The method returns a String representing the Dog object that includes the age, size, and breed. The formatted string should follow this example: I am a large husky breed dog that is 5 years old.". v. public String speak() - This method returns a String representing a Dog. Specifically, it returns the String Bark. 3. Class Cat: Create a class named Cat that is a child of Animal and has the following instance properties and public interface. a. Instance Properties: i. int numberOfLives - the number of lives the Cat has left. b. Public Interface: i. Constructors: Two constructors need to be provided. Namely a default constructor and a workhorse constructor. The default constructor will initialize the instance properties to their default values (numbers to 0 and Strings to s). Note, you must utilize the super() constructor call appropriately to set the parent's instance properties. ii. Getters and Setters for each instance property. iii. public boolean equals(Object o) The method returns true if the two Cats have the same age, size, and numberOfLives and false, otherwise. Do not forget to use the parent's equals() method when applicable. iv. public String toString() The method returns a String representing the Cat object that includes the age, size, and numberOfLives. The formatted string should follow this example: I am a small cat that is 2 years old and have 9 lives left.. v. public String speak() This method returns a String representing a Cat. Specifically, it returns the String Meow. Tester Class: In the main method of your Tester class, you must test the classes from both problems listed above. Because there are no validation checks necessary in this Lab, make sure to simply test your equals(), toString(), constructors, and speak() methods. Additional Notes: . Make sure you include JavaDoc comments for all methods and classes including parameter and return descriptions. Make sure that all classes are named correctly. There is no explicit validation checking needed for this Lab assignmentStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started