Question: 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
toLeagues converts kilometers to leagues, then returns the value. To convert to leagues, divide kilometers by
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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
