Marathon

A group of City Tech friends decide to run the New York Marathon. Their names and times (in minutes) are below:

Name Time (minutes)
Elena 341
Thomas 273
Hamilton 278
Suzie 329
Phil 445
Matt 402
Alex 388
Emma 275
John 243
James 334
Jane 412
Emily 393
Daniel 299
Neda 343
Aaron 317
Kate 265

Problem

Find the fastest runner. Print the name and his/her time (in minutes).

Optional: Find the second fastest runner. Print the name and his/her time (in minutes).

Directions

Write a method that takes as input an array of integers and returns the index corresponding to the person with the lowest time. Run this method on the array of times. Print out the name and time corresponding to the returned index.

Optional: Write a second method to find the second-best runner. The second method should use the first method to determine the best runner, and then loop through all values to find the second-best (second lowest) time.

Here is a program skeleton to get started:

class Marathon {
    public static void main (String[] arguments) {
        String[] names = {
            "Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex",
            "Emma", "John", "James", "Jane", "Emily", "Daniel", "Neda",
            "Aaron", "Kate"
        };

        int[] times = {
            341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299,
            343, 317, 265
        };

        for (int i = 0; i < names.length; i++) {
            System.out.println(names[i] + ": " + times[i]);
        }
    }
}

Submission Instructions

Submit your file Marathon.java.

Good luck!

This material is based on original materials provided by: Evan Jones, Adam Marcus, and Eugene Wu. 6.092 Introduction to Programming in Java, January IAP 2010. (Massachusetts Institute of Technology: MIT OpenCourseWare), http://ocw.mit.edu (Accessed 22 Jun, 2016). License: Creative Commons BY-NC-SA