The xxx_Pet classA Pet has a:– Name• Include an instance variable• Getters and setters for an instance variable• A toString method which returns a String containing the pet name Abstract methods: speak() and move()The subclassesWrite a dog, cat, snake subclasses with proper instant variables and methodsWrite a class xxx_TestPet which will1- Create a dog, a snake, and a cat objectsSample OutputPet Fido is a dog, weighing 45 poundsFido says woofrun Fido runPet Sam is a snake, 30 inches longSam says hissslither Sam slitherPet Hershey is a cat, with Long hairHershey says Meowprance Hershey prance2- Print just the weight of the Dog, the length of the Snake and the hair length of theCat as shown belowFido weighs 45 poundsSam has length 30 inchesHershey has Long hair 3- Store the objects in an Array of Pet objects and print the information belowPet D1 is a dog, weighing 55 poundswoofrunPet S1 is a snake, 30 inches longhissslitherPet C1 is a cat, with Long hairmeowprancePet D2 is a dog, weighing 15 poundswoofrunPet C2 is a cat, with Short hairmeowprance
The xxx_Pet class
A Pet has a:
– Name
• Include an instance variable
• Getters and setters for an instance variable
• A toString method which returns a String containing the pet name
Abstract methods: speak() and move()
The subclasses
Write a dog, cat, snake subclasses with proper instant variables and methods
Write a class xxx_TestPet which will
1- Create a dog, a snake, and a cat objects
Sample Output
Pet Fido is a dog, weighing 45 pounds
Fido says woof
run Fido run
Pet Sam is a snake, 30 inches long
Sam says hiss
slither Sam slither
Pet Hershey is a cat, with Long hair
Hershey says Meow
prance Hershey prance
2- Print just the weight of the Dog, the length of the Snake and the hair length of the
Cat as shown below
Fido weighs 45 pounds
Sam has length 30 inches
Hershey has Long hair
3- Store the objects in an Array of Pet objects and print the information below
Pet D1 is a dog, weighing 55 pounds
woof
run
Pet S1 is a snake, 30 inches long
hiss
slither
Pet C1 is a cat, with Long hair
meow
prance
Pet D2 is a dog, weighing 15 pounds
woof
run
Pet C2 is a cat, with Short hair
meow
prance
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images