Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Object Oriented Programming (java) Wild Kingdom The program that you are to write is designed to determine how long it takes for various animals to

Object Oriented Programming (java)

Wild Kingdom

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.

abstract Animal

# String kind

# double airSpeed

# double landSpeed

# boolean flies

+ abstract double FastTime (double distance)

+ void print ()

Mammal Bird

+ Mammal () + Bird ()

+ Time FastTime (double distance) + Time FastTime (double distance)

Cow Hawk

+ Cow () +Hawk ()

Bat

Bat Penguin

+ Bat () + Penguin ()

+ Time FastTime (double distance) + Time FastTime (double distance)

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. yes/no 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 main 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

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 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions