Question
Description A group of CNM friends decide to run the Boston Marathon. Their names and times (in minutes) are below: Name Time(minutes) Elena 341 Thomas
Description
A group of CNM 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).
Find the second fastest runner. Print the name and his/her time (in minutes).
Sample Output Example: (this is just an example, does not reflect the real result of the problem)
The fastest runner is: Ketty Total time: 345 minutes
The second fastest runner is: Jack Total time: 425 minutes
Instructions
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 { // class name need to be changed to Lab03.java
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
};
int i1 = fastestIndex(times); // i1 is the index of the fastest runner
// You need to use i1 to computer index of the second fastest runner
int i2 = secondFastestIndex(times, i1);
//
// your output based on the index i1 and i2
//
}
// your two Java methods:
// fastestIndex() and secondFastestIndex()
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started