Ask Question
2 November, 02:53

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

+1
Answers (1)
  1. 2 November, 03: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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers