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

  • 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.

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

  • 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”) something like that

    • 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

Thanks for the question.


Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.


// Please post the Additional Requirements as a separate question, I could have done it but at least you should have shared the details World Record Pace Times from the internet. 
Please share the Pace Table along with the question.



Thank You !!



===========================================================================


import java.util.Scanner;

public class Marathon {


    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);

        System.out.print("What if your first name? ");
        String name = scanner.nextLine();
        System.out.print("How far did you run today? ");
        double distance = scanner.nextDouble();
        System.out.print("How long it take? hours: ");
        int hours = scanner.nextInt();
        System.out.print("                ? minutes: ");
        int mins = scanner.nextInt();
        System.out.print("                ? seconds: ");
        int seconds = scanner.nextInt();

        int totalSeconds = hours * 60 * 60 + mins * 60 + seconds;
        int pace = (int) (totalSeconds / distance);

        System.out.printf("Hi %s\n", name);
        System.out.printf("Your pace is %d:%d (minutes : seconds)\n", (pace / 60), (pace % 60));


        // 1 Marathon = 26.25 miles
        int marathonTime = (int) (26.25 * pace);

        int marathonHours = marathonTime / 3600;
        marathonTime = marathonTime % 3600;
        int marathonMins = marathonTime / 60;
        int marathonSeconds = marathonTime % 60;

        System.out.printf("At this rate your marathon time would be %d:%d:%d\n",
                marathonHours ,
                marathonMins,
                marathonSeconds);

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

    }
}


Related Solutions

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
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...
Please show all work: Represent the number (+46.5) as a 32 bit floating-point number using the...
Please show all work: Represent the number (+46.5) as a 32 bit floating-point number using the IEEE standard 754 format. N.B. The attached ‘Appendix’ section may prove useful in the conversion process.             0 1000 0111 0100 0100 0000 0000 0000 000 0 1011 0100 0111 0100 0000 0000 0000 000 0 1100 0110 0101 0100 0000 0000 0000 000 0 1000 0100 0111 0100 0000 0000 0000 000 0 1010 0100 0111 0100 0000 0000 0000 000
Using the given file, ask the user for a name, phone number, and email. Display the...
Using the given file, ask the user for a name, phone number, and email. Display the required information. These are the Files that I made: import java.util.Scanner; public class Demo5 { public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println("New number creation tool"); System.out.println("Enter name"); String name = keyboard.nextLine(); System.out.println("Enter phone number"); String phoneNumber = keyboard.nextLine(); System.out.println("Enter email"); String email = keyboard.nextLine(); Phone test1 = new SmartPhone(name, phoneNumber, email); System.out.print(test1); System.out.println("Telephone neighbor: " + ((SmartPhone) test1).getTeleponeNeighbor()); }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT