Question

(JAVA) 7.12 LAB: Miles to track laps


One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input, and outputs the number of laps.

Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.print f("%.2 f", yourValue);


Ex: if the input is.

1.5

the output is:

6.00

Ex: if the input is:

2.2

the output is:

8.80

7.12 LAB: Miles to track laps One lap around a standard high-school running track is exactly 0.25 miles. Write a program that


the output is: 8.80 Your program must define and call a method: public static double milesToLaps(double userMiles) 245632.154


2 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Below is the program. As per the requirement, the track length is 0.25 miles. So multiplying the track length with 4 will make it one mile. So 4 laps are equal to one mile.

/*
* Program to convert miles to laps.
*
*/
import java.util.Scanner;

public class LabProgram {
  
   /*
   * Method to convert the miles to laps.
   * It takes input parameter userMiles and returns laps.
   * @param - double userMiles
   */
   public static double milesToLaps(double userMiles)
   {
       double laps = userMiles * 4;
       return laps;
   }
  
   public static void main(String[] args)
   {
       /*Code to call the milesToLaps() method*/
       System.out.print("Enter the Number of Miles :");
       Scanner in = new Scanner(System.in);
       double miles = in.nextDouble();
       double laps = milesToLaps(miles);
       System.out.printf("Number of laps: %.2f",laps);
      
   }

}

10/* 2 * Program to convert miles to laps. 3 4 */ 5 import java.util.Scanner; 6 7 public class LabProgram { 8 90 /* 10 * Meth

---------------------------------------------------------------------------------

output:

Run the program from eclipse. Right click on the program then click "Run As" > "Java Application".

Program ask for input of miles . Given1.5 for example below. output is displayed as 6.00

Enter the Number of Miles :1.5
Number of laps 6.00

Enter the Number of Miles :1.5 Number of laps 6.00

Add a comment
Answer #2

3.14 LAB: Track laps to miles

One lap around a standard high-school running track is exactly 0.25 miles. Define a method named lapsToMiles that takes a double as a parameter, representing the number of laps, and returns a double that represents the number of miles. Then, write a main program that takes a number of laps as an input, calls method lapsToMiles() to calculate the number of miles, and outputs the number of miles.

Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
System.out.printf("%.2f\n", yourValue);

Ex: If the input is:

7.6

the output is:

1.90

Ex: If the input is:

2.2

the output is:

0.55

The program must define and call a method:
public static double lapsToMiles(double userLaps)


Add a comment
Know the answer?
Add Answer to:
(JAVA) One lap around a standard high-school running track is exactly 0.25 miles
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (C++) One lap around a standard high-school running track is exactly 0.25 miles

    17.1 LAB: Niles to track laps  (C++)One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input, and outputs the number of laps.Output each floating-point value with two digits after the decimal point, which can be achieved by executing cout << fixed << setprecision(2); once before all other cout statements.Ex. If the input is:1.5the output is:6.00Ex: If the input is:2.2the output is:8.80Your program must define and call a function: double...

  • Code Program in C++ Language.5.9 LAB: Miles to track laps One lap around a standard...

    5.9 LAB: Miles to track lapsOne lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input, and outputs the number of laps.Ex: If the input is 1.5, the output is6Ex: If the input is 2.2, the output is8.8Your program must define and call a function:double MilesToLaps(double userMiles)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT