Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the class Distance. This class has one instance variable, a double called kilometers. The class has methods that convert the kilometers into different units.

Implement the class Distance.
This class has one instance variable, a double called kilometers. The class has methods that convert the kilometers into different units.
It should have the following methods
A constructor taking one parameter - initializes kilometers to the parameter value
toMiles - converts kilometers to miles, then returns the value. To convert to miles, divide kilometers by 1.609
toLeagues - converts kilometers to leagues, then returns the value. To convert to leagues, divide kilometers by 5.556.
doubleMiles - converts kilometers to miles, then returns double that value. Use toMiles to do the conversion.
getKilometers - returns the value of kilometers
Note that the only method that should modify the value of kilometers is the constructor.
Main Method
To test your class, create three Distance objects in main. Convert one distance to miles, one to leagues, and one to doubled miles. Print out the kilometer value and the converted value.
Here is an example of what your output could look like:

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 Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions