1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
astra-53 [7]
3 years ago
11

This class has one instance variable, a double called miles. The class has methods that convert the miles into different units.I

t should have the following methods:public Distance(double startMiles) - the constructor; initializes milespublic double toKilometers() - converts the miles to kilometers. To convert to kilometers, divide miles by 0.62137public double toYards() - converts miles to yards. To convert to yards, multiply miles by 1760.public double toFeet() - converts miles to feet. To convert to feet, multiply miles by 5280.public double getMiles() - returns the value of milesMain MethodTo test your class, create three Distance objects in main. One represents the distance between Karel and school, Karel and the park, and Karel and his best friend.Karel lives 5 miles from school. Karel lives 10 miles from the park. Karel lives 12 miles from his best friend.Your program should use the methods from Distance to print the number of:1. yards Karel lives from school2. kilometers Karel lives from the park3. feet Karel lives from his best friend
Computers and Technology
1 answer:
OverLord2011 [107]3 years ago
5 0

Answer:

The class definition with the instance variable and all the required methods is given below:

<em>public class Distance{</em>

<em>    double miles;</em>

<em>    public Distance (double startMiles) {</em>

<em>        this.miles = startMiles;</em>

<em>    }</em>

<em>    public double toKilometers ( ){</em>

<em>          double kilometerValue = miles/0.62137;</em>

<em>          return kilometerValue;</em>

<em>        }</em>

<em>    public double toYards(){</em>

<em>        double yardsValue = miles*1760;</em>

<em>        return yardsValue;</em>

<em>        }</em>

<em>    public double toFeet(){</em>

<em>        double feetsValue = miles*5280;</em>

<em>        return feetsValue;</em>

<em>        }</em>

<em>    public double getMiles(){</em>

<em>        return miles;</em>

<em>        }</em>

<em>}</em>

The main method to test the class is given in the explanation section

Explanation:

<em>public class Main {</em>

<em>    public static void main(String[] args) {</em>

<em>        Distance karelToSchool = new Distance(5.0);</em>

<em>        Distance karelToPark = new Distance(10.0);</em>

<em>        Distance karelToFriend = new Distance (12.0);</em>

<em />

<em>        double karel_Yards_From_School = karelToSchool.toYards();</em>

<em>        System.out.println("Karel's Yards from School is "+karel_Yards_From_School);</em>

<em />

<em>        double karel_kilometers_from_park = karelToPark.toKilometers();</em>

<em>        System.out.println("Karel's Kilometers from Park is "+karel_kilometers_from_park);</em>

<em />

<em>        double karel_feets_from_friend = karelToFriend.toFeet();</em>

<em>        System.out.println("Karel's Feets from Friend is "+karel_feets_from_friend);</em>

<em>    }</em>

<em />

<em>}</em>

You might be interested in
Based on the screenshot below which letter do you select to sort the items in an alphabetical order?
gladu [14]

Answer:

the smallest number start with the first number of the alphabet

6 0
3 years ago
Styles are modified by using the Office clipboard in the Home tab. true or false
cluponka [151]
Your answer is false
7 0
3 years ago
Read 2 more answers
What is the central unit of the computer that contains the logic circuitry and carries out the instructions of the computer's pr
weqwewe [10]
Well, it's called Central Processing Unit, or CPU.
8 0
4 years ago
Can you guys give some samples of STEM-related studies?​
anygoal [31]

Answer:

D :)))))

Explanation:

hope this helps

5 0
3 years ago
Read 2 more answers
Without using any additional variables, and without changing the values of ndays or the elements of the parkingTickets array, wr
dusya [7]

Answer:

Explanation:

mostTickets=0;

for (k=0; k< ndays; k++){

if (parkingTickets[k]>mostTickets) mostTickets=parkingTickets[k];

}

7 0
3 years ago
Other questions:
  • In your own words, explain the role of scientific investigation in the development of the Theory of Evolution.
    6·1 answer
  • Why might a government entity choose to offer some information and services online as in e-government
    8·2 answers
  • How to send an email
    7·2 answers
  • Which buttons should you use to publish and change a message on a message board
    6·2 answers
  • In the writing and language test of the SAT, questions ask students to do which of the following? A. Write an essay B. Define a
    14·2 answers
  • Which function should be used to display a value based on a comparison ?
    6·1 answer
  • What are the classifications of computer
    9·1 answer
  • write a program that asks the user for a month number and displays the number of days that month has?
    7·2 answers
  • How to square a number in java.
    15·1 answer
  • a(n) is an object that defines a screen element used to display information or allow the user to interact with a program in a ce
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!