Ask Question
4 January, 06:29

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. Ex: If the input is 1.5, the output is: 6.0 Ex: If the input is 2.2, the output is: 8.8 Your program should define and call a function: Function MilesToLaps (float userMiles) returns float userLaps

+3
Answers (1)
  1. 4 January, 07:13
    0
    import java. util.*;

    public class Main

    {

    public static void main (String[] args) {

    Scanner input = new Scanner (System. in);

    System. out. print ("Enter the number of miles: ");

    float miles = input. nextFloat ();

    System. out. println ("The number of laps: " + MilesToLaps (miles));

    }

    public static float MilesToLaps (float userMiles) {

    float userLaps = userMiles / 0.25F;

    return userLaps;

    }

    }

    Explanation:

    Create function called float MilesToLaps that takes one parameter, userMiles

    Calculate the user laps, dividing userMiles by 0.25 (Since all the variables are float in the question it is better to add "F" after 0.25 to avoid getting loosy conversion error) and return the user laps.

    Inside the main, ask the user for the miles. Call the the function with the miles and print the result.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers