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...
Write a program to compute the total time and average speed it will take a runner...
Write a program to compute the total time and average speed it will take a runner to run 10 miles with the following pace segments: they run the first mile at a pace of 7 minutes per mile, the following 4 miles at a pace of 8.5 minutes per mile, the next 4 miles at a pace of 9 minutes per mile and the last mile at a pace of 3.5 minutes per mile. Performs the computations and prints the...
in java we need to order a list , if we create a program in java...
in java we need to order a list , if we create a program in java what  are the possible ways of telling your program how to move the numbers in the list to make it sorted, where each way provides the required result. list the name of sorting with short explanation
Write a java program that randomizes a list and sorts it. The list will be randomized...
Write a java program that randomizes a list and sorts it. The list will be randomized to be at least 12 elements and no more than 30 elements with values between 1 and 100. You will submit one program with two sorts done separately within the program. The list will be re-randomized before reach sort. Write a flowchart for each sort.
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 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 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...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a java program: Write a nested loop program creating an array list of three positions.  The...
Write a java program: Write a nested loop program creating an array list of three positions.  The first loop terminates with a sentinel value of which user is prompted for input to continue of quit.   Inside loop to enter in each position a prompted input of person's first name.  After the inside loop, edit the second array location making its value "Boston". Print the array's contents.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT