Answer:
Here's the completed code that implements the feetToSteps method and the main program that reads the number of feet walked as input and outputs the number of steps walked:
import java.util.Scanner;
public class LabProgram {
public static int feetToSteps(double userFeet) {
double steps = userFeet / 2.5; // Convert feet to steps
return (int) Math.round(steps); // Round steps and convert to integer
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double feetWalked = scnr.nextDouble();
int stepsWalked = feetToSteps(feetWalked);
System.out.println(stepsWalked);
scnr.close();
}
}
Step-by-step explanation:
In this code, the feetToSteps method takes a double parameter userFeet, representing the number of feet walked, and converts it to the number of steps walked by dividing it by 2.5 (since 1 step = 2.5 feet). The result is then rounded to the nearest integer using the Math.round method and casted to an integer before being returned.
The main program reads the number of feet walked as input using a Scanner object, calls the feetToSteps method with the input as an argument, and outputs the number of steps walked using System.out.println. Finally, the Scanner object is closed to free up system resources.