Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions