Question: 4 -(Code only) Create a class called Pet which contains: - A field for the name of the pet - A field for the age

 4 -(Code only) Create a class called Pet which contains: -

4 -(Code only) Create a class called Pet which contains: - A field for the name of the pet - A field for the age of the pet - Appropriate constructor and accessors Create a class called Dog which extends the Pet class and has: - A field for breed of dog - A field for body weight Appropriate constructor and accessors - A toString method that prints the name, age, breed and weight of the dog Create a class called Cat which extends the Pet class and has: - A field that describes the coat of the cat (example: short/long/plush/silky/soft) - A field for whether it is a lap cat Appropriate constructor and accessors - A toString method that prints the name, age and coat type of the cat, and whether it is a lap cat Create a class called Fish which extends the Pet class and has: - A field for type of fish - A field for the color of its scales Appropriate constructor and accessors - A toString method that prints the name, age, type and scale color of the fish Write a main which asks the user to enter the number of pets (n) and then ask for the details for each pet. Ask for the correct information depending on the type of pet. Create a Dog,Cat or Fish object as required. Add each pet to an ArrayList of Pets. After all information is entered and stored, print out the gathered information of all objects in the list, starting with the all the Fish first, then Cats and then Dogs. Hint: You can use the instanceOf operator to find out if a pet is a fish, cat or dog Name your main class Hw5pr4 and your file Hw5pr4.java. Turn in all .java files

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!