Create abstract class Pet , which is the abstract superclass of all animals. Declare a integer attribute called legs, which records the number of legs for this animal. Define a constructor that initializes the legs attribute. Declare an abstract method eat. Declare a concrete method walk that prints out something about how the animals walks (include the number of legs). Create the Dog class. The Dog class extends the Pet class. This class must include a String attribute to store the name and food of the pet Define a default constructor that calls the superclass constructor to specify that all dogs have 4 legs and name. override the eat and walk method. Create the Cat class that extends Pet. This class must include a String attribute to store the name of the pet, and a string to save food . Define a constructor that takes one String parameter that specifies the cat's name and food. This constructor must also call the superclass constructor to specify that all cats have four legs. Override walk method. Implement the eat method. Create the Fish class with fins, food this  also extends pet, Override the Pet methods to specify that fish can't walk and don't have legs, implement eat method. Create a PetOwner Class which represents a person who have pets, this class contain name, age, and pet , Provide appropriate methods for the class. Create an TestAnimals program: Create an arraylist of type PetOwner and then by asking about type of pet one want add that type pet to the arraylist. e.g.     if(choice== cat){                  Cat cat=new Cat(“meow”);                    PetOwner p=new PetOwner(“ali”,cat)’;                     arraylist.add(p);  } Same for dog and fish, at the end print arraylist also call eat and walk methods.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2GZ
icon
Related questions
Question
  1. Create abstract class Pet , which is the abstract superclass of all animals.
    1. Declare a integer attribute called legs, which records the number of legs for this animal.
    2. Define a constructor that initializes the legs attribute.
    3. Declare an abstract method eat.
    4. Declare a concrete method walk that prints out something about how the animals walks (include the number of legs).
  2. Create the Dog class.
    1. The Dog class extends the Pet class.
    2. This class must include a String attribute to store the name and food of the pet
    3. Define a default constructor that calls the superclass constructor to specify that all dogs have 4 legs and name.
    4. override the eat and walk method.
  3. Create the Cat class that extends Pet.
    1. This class must include a String attribute to store the name of the pet, and a string to save food .
    2. Define a constructor that takes one String parameter that specifies the cat's name and food. This constructor must also call the superclass constructor to specify that all cats have four legs.
    3. Override walk method.
    4. Implement the eat method.
  4. Create the Fish class with fins, food this  also extends pet, Override the Pet methods to specify that fish can't walk and don't have legs, implement eat method.
  5. Create a PetOwner Class which represents a person who have pets, this class contain name, age, and pet , Provide appropriate methods for the class.
  6. Create an TestAnimals program:

Create an arraylist of type PetOwner and then by asking about type of pet one want add that type pet to the arraylist.

e.g.     if(choice== cat){

                 Cat cat=new Cat(“meow”);

                   PetOwner p=new PetOwner(“ali”,cat)’;

                    arraylist.add(p);

 }

Same for dog and fish, at the end print arraylist also call eat and walk methods.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,