Here will go through how I chose to solve Assignment 3 from Intro to Programming in Java as taught at MIT. All course related documents and files are linked below.

In this assignment we are tasked with sorting an array and displaying a specific result.

A group of MIT friends decide to run the Boston Marathon. Their names and times (in minutes) are below: Name

Time (minutes)

































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.


I decided to solve the problem a bit differently.  Using the result of the first method doesn’t really help in finding the second runner.  You are basically doing what the first method does again with just one less possibility.

Instead I chose to write a method that sorts both arrays into order from fastest to slowest time.  Then displaying first and second place is as simple as printing the first and second positions in the arrays.

Screenshot 2015-09-08 23.12.17

The main method contains the original lists, the method calls to sort the lists, and the command to display them.  The real meat of the program is in the two list ordering methods.

Our first sort method sorts the array of the times.

Screenshot 2015-09-08 23.15.15

We feed the method the two arrays we are supplied by the assignment.  We then bubble sort them and output the resulting ordered list of race times.

The second method takes the same input but instead returns the ordered list of racers.

Screenshot 2015-09-08 23.18.33

That’s it for Assignment 3.  I’d appreciate any feedback or perhaps a more elegant solution.

Resource Links

MIT Course Homepage
Original Assignment
My Solution



The Gift of Light

September 5, 2015
Thumbnail image for The Gift of Light

We use light to illuminate our streets, to read books late after sunset, and to decorate our homes and trees at Christmas time. Light is a wonderful thing! I would like your help in giving the gift of light to schools around the world that are without power.

Read the full article →

Intro to Programming in Java: Assignment 2

September 2, 2015
Thumbnail image for Intro to Programming in Java: Assignment 2

Here will go through how I chose to solve Assignment 2 from Intro to Programming in Java as taught at MIT. All course related documents and files are linked below. In this assignment we are tasked with calculating and displaying the total pay of three employees of the hypothetical Foo Corporation. The calculation must adhere […]

Read the full article →

Intro to Programming in Java: Assignment 1

September 2, 2015

In this assignment you are tasked with calculating the location of an object after 10 seconds of free fall under Earth’s gravity.

Read the full article →

Question and Answer by Charles Bukowski

July 21, 2015

he sat naked and drunk in a room of summer
night, running the blade of the knife
under his fingernails, smiling, thinking

Read the full article →

How Self-Driving Cars Will Put Taxis And Parking Lots Out Of Business

June 2, 2014

Inevitability. When the first light bulb turned on the day of the candle was done. I’m not saying if you are a taxi cab driver or parking garage owner you should give up immediately, you’ve definitely got time.  But time, as they say, is not on your side.  Follow me… The car pulls up to […]

Read the full article →

InMotion Hosting

March 26, 2014

Dear Readers, This website for its entire existence has been hosted by InMotion Hosting. Why am I telling you this? Because they rock! Before I even dig into the features they offer I want to highlight their customer service. Are there cheaper web hosts? Of course. Are there web hosts that offer more features? Actually […]

Read the full article →

Syncing your cloud storage with cloudHQ

March 25, 2014

Google Drive has become my go-to service for almost all things cloud. Sure I have a Pogoplug and a Dropbox, but all of my documents and all of my photos are stored through Google’s cloud service. However, despite my heavy Google dependence I still find myself loving Evernote. When I want to casually journal, take […]

Read the full article →

Happy Birthday Professor Tolkien!

January 3, 2013

Today is J. R. R. Tolkien’s birthday!  Celebrate by reading some of his works, eating some lembas bread or other foods from Arda, and don’t forget to smoke some Old Toby with your favorite churchwarden pipe! Click here to learn more about Tolkien. Don’t forget to join in on the annual birthday toast! J. R. […]

Read the full article →

The Principle of Self-Ownership

October 13, 2012
Thumbnail image for The Principle of Self-Ownership

My philosophy is based on the principle of self-ownership. You own your life. To deny this is to imply that another person has a higher claim on your life than you do.

Read the full article →