solve this by arraylist in the last of the question it has been told 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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

solve this by arraylist in the last of the question it has been told

  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 7 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY