(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
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);
}
}
---------------------------------------------------------------------------------
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
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)
(JAVA) 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...
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)