'Lab Activity; Track Laps To Miles
this is one of the labs for my college class and with this one, I don't really know what to do. These are the instructions: 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)
This is what I have so far: import java.util.Scanner;
public class LabProgram {
public static double lapsToMiles(double userLaps) {
userLaps = userMiles/0.25;
return double userLaps;
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double userLaps = scnr.nextDouble();
userLaps.lapsToMiles();
System.out.printf("%.2f\n", lapsToMiles);
}
}
I've been having trouble with it, I don't know if I set it up right.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
