title: Printing the lowest and second lowest values in an array using methods (Java)
body: <p>I am new to Java and have been given an assignment that asks:</p>
  
  <p><strong>Description</strong></p>
  
  <p>A group of friends decide to run the Boston Marathon. Their names and times (in minutes) are below:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Find the fastest runner. Print the name and his/her time (in minutes).</p>
  
  <p>Find the second fastest runner. Print the name and his/her time (in minutes).</p>
  
  <p><strong>Instructions</strong></p>
  
  <p>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:</p>
  
  <pre><code>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
   };
   int i1 = fastestIndex(times);
   int i2 = secondFastestIndex(times);
   //
   // your output based on the index i1 and i2
   //
   }
   // your two Java methods:
   // fastestIndex() and secondFastestIndex()
  }
  </code></pre>
  
  <p>I wrote a program that prints the first and second place times and names but now I am starting to think I didn't follow the instructions correctly. Could anyone help me figure out what I should do differently?</p>
  
  <p>Here is my amateur code:</p>
  
  <pre><code>public class Lab
  {
      public static void main(String[] args)
      {
          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 firstplace = times[0];
          String firstname = names[0];
  
          int secondplace = times[0];
          String secondname = names[0];
  
          for (int counter = 0; counter &lt; times.length; counter++)
          {
              if (times[counter] &lt; firstplace) {
                  firstplace = times[counter];
                  firstname = names[counter]; }
          }
  
          for (int counter = 0; counter &lt; times.length; counter++)
          {
              if (times[counter] &gt; firstplace)
                  if (times[counter] &lt; secondplace) {
                      secondplace = times[counter];
                      secondname = names[counter]; }
          }
              System.out.printf("The fastest runner is: %s (%d Minutes)%n", firstname, firstplace);
              System.out.printf("The second fastest runner is: %s (%d Minutes)%n", secondname, secondplace);
          } // end main
      } // end class Lab
  </code></pre>
  
  <p>This is what it prints:</p>
  
  <pre><code>The fastest runner is: John (243 Minutes)
  The second fastest runner is: Kate (265 Minutes)
  </code></pre>