. Create abstract class Pet , which is the abstract super class of all animals. 1. Declare an 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 that implements Pet class. 1. This class must include a String attribute to store the name and food of the pet 2. Define a default constructor that calls the super class constructor to specify that all dogs have 4 legs and name. 3. override the eat and walk method. 3. Create the Cat class that Implements Pet class. 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. This constructor must also call the super class constructor to specify that all cats have four legs. 3. Define another constructor that takes no parameters. Have this constructor call the previous constructor (using this keyword) and pass an empty string as the argument. 4. Override walk method. 5. Implement the eat method. 4. Create the Fish class with fins, food. 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 Test Animals 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.
1. Create abstract class Pet , which is the abstract super class of all animals.
1. Declare an 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 that implements Pet class.
1. This class must include a String attribute to store the name and food of the pet
2. Define a default constructor that calls the super class constructor to specify that all dogs have 4 legs and name.
3. override the eat and walk method.
3. Create the Cat class that Implements Pet class.
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. This constructor must also call the super class constructor to specify that all cats have four legs.
3. Define another constructor that takes no parameters. Have this constructor call the previous constructor (using this keyword) and pass an empty string as the argument.
4. Override walk method.
5. Implement the eat method.
4. Create the Fish class with fins, food. 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 Test Animals 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.
Trending now
This is a popular solution!
Step by step
Solved in 7 steps with 2 images