I am trying to create a method that returns the fastest marathon time from an array (int times[]) of times, and also gives the corresponding name of the individual who ran that time. The names of individuals are in a separate array (String names[]). The order of times[] corresponds to the order of names[], meaning the name of the person in names[0] has a running time of times[0], and so on.
I have been able to return the lowest integer from times[]. I am having trouble figuring out how to link the lowest time to the name of the runner, and print both values (e.g., names[0] + ": " + times[0]). Any help would be appreciated.
*I would like to see how this is done without the use of a pair class.
Here is my code thus far.
public class Marathon {
static int i = 0;
public static Integer firstPlace(int[] value) {
int time = value[0];
while (i < value.length) {
if (value[i] > time) {
time = value[i];
i++;
} else {
i++;
continue;
}
}
return time;
}
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
};
System.out.println(Marathon.firstPlace(times));
}
}