Hey guys, my name's Theo, or Thedore. I am currently doing the MIT open courseware java class, an am having a bit of trouble understanding how exactly to do this problem dealing with arrays. Any help would be appreciated!
A group of MIT friends decide to run the Boston 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
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).
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.
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]);
}
}
}
Submit your file Marathon.java via Stellar.
Good luck!