Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions

Question

Question Can I collect benefits if I become disabled?

Answered: 1 week ago

Question

Question May I set up a Keogh plan in addition to an IRA?

Answered: 1 week ago