Please Code Java Implement Class Distance Class One Instance Variable Double Called Miles Q43866531
Please Code in Java
Implement the class Distance.
This class has one instance variable, a double called miles. Theclass has methods that convert the miles into different units.
It should have the following methods
- public Distance(double startMiles) – the constructor;initializes miles
- public double toKilometers() – converts the miles tokilometers. To convert to kilometers, divide miles by 0.62137
- public double toYards() – converts miles to yards. To convertto yards, multiply miles by 1760.
- public double toFeet() – converts miles to feet. To convert tofeet, muliply miles by 5280.
- public double getMiles() – returns the value of miles
Main Method
To test your class, create three Distance objects in main. Onerepresents the distance between Karel and school, Karel and thepark, and Karel and his best friend.
Karel lives 5 miles from school. Karel lives 10 miles from thepark. Karel lives 12 miles from his best friend.
Your program should use the methods from Distance to print thenumber of
- yards Karel lives from school
- kilometers Karel lives from the park
- feet Karel lives from his best friend
Expert Answer
Answer to Please Code in Java Implement the class Distance. This class has one instance variable, a double called miles. The class…
OR