Question

In: Computer Science

We have a list of runner and their running time, write a program in Java to...

We have a list of runner and their running time, write a program in Java to show the fastest runner and their time.

Solutions

Expert Solution

public class Main
{
        public static void main(String[] args) {
        
        //initialize array of names
         String[] names = {
                "Alexa", "Lilly", "Sharon", "Emma", "Joey", "Matt",
                "phoebe", "Jack", "David", "James"};
    
        //initialize array of running time ffor each runner
        int[] runningtime = {
                402, 341, 388, 278, 329, 445, 341, 273, 334, 500};

        //initialoze temp to 0
        int temp = 0;
        for (int i = 0; i < runningtime.length; i++) {
            
            /* fastest runner is the one who completes distance
            in minimum running time. find the minimum running time from the array 
            runningtime and store the index of minimum running time in temp variable.
            if running time of ith player is lower compare to first player 
            then temp becomes i. */
            if (runningtime[i] < runningtime[temp]) {
                temp = i;
            }
        }        
        
        //print the fastest runner as temp represents the index of the fastest runner
        System.err.println("Fastest runner: " + names [temp]);
        System.err.println( "Running Time of "+ names[temp] + ": " + runningtime[temp]);

    }

}

OUTPUT:


Related Solutions

Write the following java program: Desc Output the name and time of the runner who came...
Write the following java program: Desc Output the name and time of the runner who came in first, as well as the name and time of the runner who came in last in a marathon race (assuming there are no ties). Input A text file named marathon.txt containing the name and time of each participant in the following format (the file has at least 1 participant, name is just 1 word with no space, and name and time are separated...
What we want the program to do: We need to write a program, in Java, that...
What we want the program to do: We need to write a program, in Java, that will let the pilot issue commands to the aircraft to get it down safely on the flight deck. The program starts by prompting (asking) the user to enter the (start) approach speed in knots. A knot is a nautical mile and is the unit used in the navy and by the navy pilots. After the user enters the approach speed, the user is then...
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
Write an algorithm to evaluate an infix expression in Java. Calculate its running time
Write an algorithm to evaluate an infix expression in Java. Calculate its running time
Write a Java program that prompts the user to enter a list of integer values and...
Write a Java program that prompts the user to enter a list of integer values and displays whether the list is sorted in increasing order or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. <Output> Enter list: 8 101516619111 The list is not sorted <End Output <Output> Enter list: 10 11344579 11 21 The list is already sorted <End Output Create a complete class for...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
Write a Java program to implement a Single Linked List that will take inputs from a...
Write a Java program to implement a Single Linked List that will take inputs from a user as Student Names. First, add Brian and Larry to the newly created linked list and print the output Add "Kathy" to index 1 of the linked list and print output Now add "Chris" to the start of the list and "Briana" to the end of the list using built-in Java functions. Print the output of the linked list.
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list...
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list of integers from use input and has the following methods: 1. min - Finds the smallest integer in the list. 2. max- Finds the largest integer in the list. 3. average - Computes the average of all the numbers. 4. main - method prompts the user for the inputs and ends when the user enter Q or q and then neatly outputs the entire...
Create a new Java program named AllAboutMe (For JAVA we use blue J) Write code to...
Create a new Java program named AllAboutMe (For JAVA we use blue J) Write code to have the program print your name, favorite color, and three hobbies to a new text file called “AllAboutMe” using PrintStream. Submit code.
Does 10K running time change when the runner listens to music? Nine runners were timed as...
Does 10K running time change when the runner listens to music? Nine runners were timed as they ran a 10K with and without listening to music. The running times in minutes are shown below. Running Time With Music 38 47 45 51 40 34 38 51 44 Without Music 45 55 50 54 44 43 38 55 46 Assume a Normal distribution. What can be concluded at the the α = 0.05 level of significance? For this study, we should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT