Question

In: Computer Science

Using Java, Ask for the runner’s name Ask the runner to enter a floating point number...

Using Java,

  1. Ask for the runner’s name

  2. Ask the runner to enter a floating point number for the number of miles ran, like 3.6 or 9.5

  3. Then ask for the number of hours, minutes, and seconds it took to run

  4. Format the numbers with leading 0's if the pace is 8 minutes and 3 second, it should be 8:03 and for marathon time, if its 1 hour and 15 minutes and 9 seconds, it should be 1:15:09

  5. Please read through the whole thing, as the pace table example and fastest man time is listed below...

  • A marathon is 26.219 miles

  • Pace is how long it takes in minutes and seconds to run 1 mile.

Example Input:
What is your first name? // user enters Pheidippides
How far did you run today? 10.6 // user enters 10.6 miles

How long did it take? Hours: 1 // user enters 1 hours

Minutes: 34 // user enters 34 minutes

Seconds: 17 // user enters 17 seconds

Example Output:

Hi Pheidippides
Your pace is 8:53 (minutes: seconds)
At this rate your marathon time would be 3:53:12
Good luck with your training!

After your program tells the user what their pace is, your program will build a table showing the following columns. The pace table should start with the fastest man time which is Eliud Kipchoge with a pace of 4:37 and 2:01:04 and continue in 17 minute and 37 second intervals until you reach the marathon time of the user.

Example: (THE PACE TABLE EXAMPLE)

Pace Table
Pace Marathon
4:37 2:01:04 ←- Eliud Kipchoge
5:17 2:18:41
5:57 2:36:18
6:37 2:53:55
7:18 3:11:32
7:58 3:29:09
8:38 3:46:46
8:53 3:53:12 ← Pheidippides






HINTS

  • The table should start with the World Record pace and time which is 4:37, 2:01:04.

  • Then continues in 17 minute and 37 second intervals until you reach the marathon time of the user.

  • Use a static function to print the pace table, introduce a while loop.

  • For the first person it should call a printTable function

    • Example : printTable (pace, “<--- Eliud Kipchoge”)

    • The pace table continues until it reaches the user

    • printTable (myPace, name) something like that  

  • For the marathon and pace time, make sure the format has 0’s if the time is 9 seconds, it should be 09.

  • Use the printf statement for formatting output (“02d %f%s”)

Solutions

Expert Solution

// Java program to calculate the pace and marathon time and display a pace table

import java.util.Scanner;

public class MarathonPaceTable {

      

       public static void main(String[] args) {

             Scanner scan = new Scanner(System.in);

             String name;

             int hours, mins, secs;

             double distance;

             double marathonDistance = 26.219;

             // input of runner's name

             System.out.print("What is your first name? ");

             name = scan.nextLine();

             // input of miles ran

             System.out.print("How far did you run today? ");

             distance = scan.nextDouble();

             // input of time taken to run the given miles in hours, mins and secs

             System.out.print("How long did it take?\nHours: ");

             hours = scan.nextInt();

             System.out.print("Minutes: ");

             mins = scan.nextInt();

             System.out.print("Seconds: ");

             secs = scan.nextInt();

            

             int paceMins, paceSecs;

             // calculate the total time in seconds

             int totalSecs = (hours*3600) + (mins*60) + secs;

             double pace = totalSecs/distance; // calculate pace in seconds

             // convert pace to mins:secs

             paceMins = (int)(pace/60);

             pace -= (paceMins*60);

             paceSecs = (int)pace;

             // output the name and pace

             System.out.println("Hi "+name);

            

             System.out.printf("Your pace is %d:%02d (minutes: seconds)",paceMins,paceSecs);

            

             // calculate marathon time

             double totalSecsPerMile = totalSecs/distance;

             double marathonTime = marathonDistance*totalSecsPerMile;

            

             int marathonHours = (int)(marathonTime/3600);

             marathonTime -= (marathonHours*3600);         

             int marathonMins = (int)(marathonTime/60);

             marathonTime -= (marathonMins*60);

             int marathonSecs = (int)marathonTime;

            

             // output the marathon time

                          

             System.out.printf("\nAt this rate your marathon time would be %d:%02d:%02d",marathonHours,marathonMins,marathonSecs);

             System.out.println("\nGood luck with your training!");

            

             // set the initial variables for the pace table

             System.out.printf("\n%-5s %-15s","Pace","Marathon");

             int startPaceMin = 4, startPaceSec = 37;

             int startMarathonHr = 2, startMarathonMin = 1, startMarathonSec = 4;

             String paceStr = String.format("%d:%02d %d:%02d:%02d", startPaceMin,startPaceSec,startMarathonHr,startMarathonMin,startMarathonSec);

             printTable (paceStr, "<--- Eliud Kipchoge");

             // loop that continues till we reach the marathon time of user

             while(true)

             {

                    // get the next marathon time

                    startMarathonSec += 37;

                    if(startMarathonSec >= 60)

                    {

                           startMarathonMin++;

                           startMarathonSec = startMarathonSec-60;

                    }

                   

                    startMarathonMin += 17;

                    if(startMarathonMin >= 60)

                    {

                           startMarathonHr++;

                           startMarathonMin = startMarathonMin - 60;

                    }

                   

                    if(startMarathonHr > marathonHours )

                           break;

                    else if(startMarathonHr == marathonHours)

                    {

                           if(startMarathonMin > marathonMins)

                                 break;

                           else if(startMarathonMin == marathonMins)

                                 if(startMarathonSec >= marathonSecs)

                                        break;

                    }

                    // calculate the pace

                    double total = (double)(startMarathonHr*3600 + startMarathonMin*60 + startMarathonSec);

                    double paceTime = total/marathonDistance;

                    startPaceMin = (int)(paceTime/60);

                    paceTime -= (startPaceMin*60);

                    startPaceSec = (int)paceTime;

                    // output the pace

                    paceStr = String.format("%d:%02d %d:%02d:%02d", startPaceMin,startPaceSec,startMarathonHr,startMarathonMin,startMarathonSec);

                    printTable (paceStr, "");

             }

            

             // calculate the pace for the user

             double total = (double)(startMarathonHr*3600 + startMarathonMin*60 + startMarathonSec);

             double paceTime = total/marathonDistance;

             startPaceMin = (int)(paceTime/60);

             paceTime -= (startPaceMin*60);

             startPaceSec = (int)paceTime;

             // output the pace for the user

             paceStr = String.format("%d:%02d %d:%02d:%02d", paceMins,paceSecs,marathonHours,marathonMins,marathonSecs);

             printTable (paceStr, "<- "+name);

            

            

             scan.close();

       }

      

       // method to display the pace and user name in tabular format

       public static void printTable(String pace, String name)

       {

             System.out.printf("\n%-20s%s",pace,name);

       }

}

//end of program

Output:


Related Solutions

Using Java, Ask for the runner’s name Ask the runner to enter a floating point number...
Using Java, Ask for the runner’s name Ask the runner to enter a floating point number for the number of miles ran, like 3.6 or 9.5 Then ask for the number of hours, minutes, and seconds it took to run A marathon is 26.219 miles Pace is how long it takes in minutes and seconds to run 1 mile. Example Input: What is your first name? // user enters Pheidippides How far did you run today? 10.6 // user enters...
Convert the following floating-point number (stored using IEEE floating-point standard 754) to a binary number in...
Convert the following floating-point number (stored using IEEE floating-point standard 754) to a binary number in non-standard form. 0100_0001_1110_0010_1000_0000_0000_0000
Write the following program in Java. Ask the user to enter the number of rows and...
Write the following program in Java. Ask the user to enter the number of rows and columns for a 2-D array. Create the array and fill it with random integers using (int)(Math.random() * 20) (or whatever number you choose). Then, provide the user with several menu choices. 1. See the entire array. 2. See a specific row. 3. See a specific column. 4. See a specific value. 5. Calculate the average of each row. 6. Calculate the total of each...
Using the simple model for representing binary floating point numbers A floating-point number is 14 bits...
Using the simple model for representing binary floating point numbers A floating-point number is 14 bits in length. The exponent field is 5 bits. The significand field is 8 bits. The bias is 15 Represent -32.5010 in the simple model.
Using Java! Write a program that ask prompt the user to enter a dollar amount as...
Using Java! Write a program that ask prompt the user to enter a dollar amount as double. Then, calculate how many quarters, dimes, nickels and pennies are in the dollar amount. For example: $2.56 = 10 quarters, 1 dime, 1 nickel and 1 cent. Print all of the values. Hint: Use Modulus operator and integer division when necessary.
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
11) Enter the following using Java. Use for loop to enter student id, student name, major...
11) Enter the following using Java. Use for loop to enter student id, student name, major and grades. Also grades should display their letter grades based on their conditions. After that display the name of students and their info, and also their letter grade After that display the sum of all grades and the average Output Example: Student ID: 0957644 Student Name: Pedro Hernandez Student Major: Business Information Systems Grades for Fall 2020: Introduction to Computer Science using Java: 85,...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the user to enter the student names and scores as shown. Output the name and score of the student with the 2nd lowest score. NOTE: You may assume all students have distinct scores between 0 and 100 inclusive and there are at least 2 students NOTE: You may only use what has been taught in class so far for this assignment. You are not allowed...
Write a JAVA program that allow a user to enter 2 number, starting point and end...
Write a JAVA program that allow a user to enter 2 number, starting point and end point. For example a user me enter 1 and 100. Your program will Add numbers from 1 to 100, add all the even number, and add all the odd numbers Output: The sum of number 1 to 100 is: The sum of even number 1 to 100 is: The sum of odd number 1 to 100 is:
JAVA Write a Temperature class that has two instance variables: a temperature value (a floating-point number)...
JAVA Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degrees if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius). Include the following: (1) two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT