Question
The program that you are to write is designed to determine how long it takes for various animals to travel different distances. A number of
The program that you are to write is designed to determine how long it takes for various animals to travel different distances. A number of classes will be used. The following diagram describes an inheritance hierarchy of animals. # indicates a protected field.
Some comments about each class:
Animal (abstract class):
kind is the name of the animal
airSpeed and landSpeed are the speed in miles per hour that an animal can move through the air and on the groun
flies is true if the animal can fly
The FastTime is an abstract method that returns the amount of time in hours the animal will take to cover the given distance.
The print method prints the four protected data items, one per line, with labels. yeso is indicated for flying.
Mammal:
The constructor notes that the animal cannot fly
The FastTime method is defined to give the time that the animal will take to make the trip on the ground
Bird:
The constructor notes that the animal can fly
The FastTime method is defined to give the time that the animal will take to make the trip through the air.
Cow:
The constructor indicates that the animal is a Cow, travels 5 mph on land and 0 mph through the air.
Hawk:
The constructor indicates that the animal is a Hawk, travels 2 mph on land and 40 mph through the air.
Bat:
The constructor indicates that the animal is a Bat, can fly, travels 1 mph on land and 22 mph through the air.
The FastTime method is overridden to give the time that the bat will take to make the trip through the air.
Penguin:
The constructor indicates that the animal is a Penguin, cannot fly, travels 1.5 mph on land and 0 mph through the air.
The FastTime method is defined to give the time that the penguin will take to make the trip on the ground.
Write a Java application that repeatedly asks the user for an animal and a trip and, for each, prints the attributes of the animal and the length of time needed for the trip. You will declare an Animal object and use an appropriate constructor to cast it as a given animal. Travel time should be printed with two digits after the decimal. Here is a sample run (user input in bold):
Enter an animal (or quit): penguin
Enter a distance to travel: 5
Kind: Penguin
Air Speed: 0.0
Land Speed: 1.5
Can Fly: No
Time for trip: 3.33 hours
Enter an animal (or quit): cow
Enter a distance to travel: 7
Kind: Cow
Air Speed: 0.0
Land Speed: 5.0
Can Fly: No
Time for trip: 1.4 hours
Enter an animal (or quit): bat
Enter a distance to travel: 4
Kind: Bat
Air Speed: 22.0
Land Speed: 1.0
Can Fly: Yes
Time for trip: 0.18 hours
Enter an animal (or quit): hawk
Enter a distance to travel: 22
Kind: Hawk
Air Speed: 40.0
Land Speed: 2.0
Can Fly: Yes
Time for trip: 0.55 hours
Enter an animal (or quit): quit
abstract Animal # String kind # double airspeed # double landSpeed # boolean flies + abstract double FastTime, (double distance) + void print 0 Mammal Bird + Mammal 0 + Bird 0 + Time FastTime (double distance) Time EastTine (double distance) Cow Hawk + Hawk C Bat Penguin + Penguin O + Time FastTime (double distance) Time EastTius (double distance)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