Answered step by step
Verified Expert Solution
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
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
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