Answered step by step
Verified Expert Solution
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
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
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