Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise - 3: Marathon - One-dimensional Array A group of friends decide to run a Marathon[1]. Their names and times (in minutes) are below: Name

Exercise - 3: Marathon - One-dimensional Array

A group of friends decide to run a Marathon[1]. 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

What to Do: 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. Here is a program skeleton to get started:

class Marathon {

public static void main (String[] args) {

String[] names = { "Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex", "Emma", "John", "James", "Jane", "Emily"};

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

for (int i = 0; i < names.length; i++) {

System.out.println(names[i] + ": " + times[i]);

}

}

}

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions