Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a blackboard.ncat.edu COMP163 Marathon Pace Lab Marathon runners sometimes want

ID: 3888415 • Letter: A

Question

a blackboard.ncat.edu COMP163 Marathon Pace Lab Marathon runners sometimes want to know the pace they must maintain to achieve a given time. Write a program that will calculate their pace as minutes and seconds per mile to achieve their goal time for a 26.2 mile marathon. The goal time is specified in hours and minutes. e program should Inp Th ut the goal hours and minutes. Calculate the goal in minutes by multiplying the hours by 60 and adding minutes. Divide the goal time by 26.2 to get the pace time in minutes per mile. Convert to an int to get just the minutes: int paceMin = (int) paceTime; Calculate the seconds of the pace: int pacesec = (int) ( (paceTime -paceMin) * 60.0) ; Display the minutes and seconds with a colon between them. You can write the program as a command line application with a maximum possible score of 75 points or you can write the program with a Graphical User Interface for a maximum possible score of 100. Write the program as an application or with a GUI Do not do both. For a maximum of 75 points, you can write the program as a Java application. Example output Enter the hour and minutes of the goal time 3 52 The necessary pace is 8:51 For a maximum of 100 points, you can write the program a Java program with a Graphical User Interface Enter goal time in Hours:minutes 2 Calc pace 4:41 Note that good comments are necessary for a good grade

Explanation / Answer

import java.util.*;

// class Marathon

public class Marathon

{

    // main method

    public static void main(String[] args)

    {

        // create a scanner object

        Scanner sc=new Scanner(System.in);

       

        int hours, minutes;

        System.out.println("Enter the hour and minutes of the goal time");

       

        // scan hours and minutes

        hours = sc.nextInt();

        minutes = sc.nextInt();

       

        // compute goal time in minutes

        double goalTime = hours * 60 + minutes;

       

        // compute pace time in minutes per mile

        double paceTime = goalTime / 26.2;

       

        // calculate pace minutes

        int paceMin = (int)paceTime;

       

        // calculate seconds of the pace

        int paceSec = (int)((paceTime - (double)paceMin) * 60);

       

        System.out.println("The necessary pace is : " + paceMin + ":" +paceSec);

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote