/**
 * Exercise for students to write code to read and track contributors.
 * @author  Terry Sergeant
 * @date    04 Dec 2006
 *
 * A text file named "contrib.txt" contains a list of people and the dollar
 * amount (no cents) of their contribution.  You will write a program that
 * will read the contributors names and the contribution amounts into 
 * parallel arrays.  Then you will sort the entries by calling the
 * pre-written sort function.  Then you will write a function that will
 * display the top 10 contributors and the bottom 10 contributors.  You
 * will write and call another function that will calculate (and return)
 * the total dollar amount of contributions.
 *
 * The function headers have already been written.  You simply need to
 * complete the functions and modify main() to make use of them.  You
 * should not change the existing headers and you should use the
 * variables that were declared in main.  Use the documentation of each
 * function to guide you in what the function is intended to do.
 *
 * If you don't know where to start then here are some ideas:
 * 1. Open the input file (contrib.txt) and view its layout.
 * 2. Copy the input file and shorten it to contain about 30 entries.
 * 3. Add code to readFromFile to open and close the test file.  Of
 *    course you will compile and test after each step!  (This will 
 *    require you to add a call to the function in main).
 * 4. Add code to read from the file and display contents (not using
 *    the arrays yet).
 * 5. Modify the code to read into the arrays.  (This will require reserving
 *    memory for the arrays in main).
 * 6. Write the display function so that it displays *all* of the entries
 *    in the array.  Call the function from main.  Test it.
 * 7. Add call to the sort function in main.  Display all results.
 * 8. Modify display() to show only top/bottom 10.
 * 9. Finish totalContributions method.  Call it from main.
 * 10. Use the original (big) input file instead of your shortened one.
 *     Test everything.
*/

import java.util.Scanner;
import java.io.IOException;
import java.io.File;

public class Contributions
{
  public static void main(String [] args) 
  {
    String [] names;   // list of names of contributors
    int [] amounts;    // dollar amounts of contributions 
    int n;             // number of contributors

  }

  /**
   * Read name and contribution amounts from 'contrib.txt'.
   *
   * @param names Array to hold the name of each contributor.
   * @param amt   Array to hold the name of each contributor.
   * @return The number of contributions read from the file.
  */
  public static int readFromFile(String [] names, int [] amt)
  {

    return 0;
  }


  /**
   * Display the top 10 and bottom 10 contributors.
   * NOTE: We assume that the list has been sorted with the largest
   * contributors being listed first.  We also assume that there are
   * at least 20 contributors.
   *
   * @param names Array to hold the name of each contributor.
   * @param amt   Array to hold the name of each contributor.
   * @param n     The number of contributions stored in the arrays.
  */
  public static void display(String [] names, int [] amt, int n)
  {
  }


  /**
   * Calculates the total dollar amount of all contributions.
   * NOTE: We return a "long" because an int isn't big enough
   * to hold the answer.
   *
   * @param amt   Array to hold the name of each contributor.
   * @param n     The number of contributions stored in amt.
   * @return      A long value represented the sum of contributions.
  */
  public static long totalContributions(int [] amt, int n)
  {

    return 0;
  }


  /**
   * Sorts entries from highest contribution to lowest contribution.
   * NOTE: This is a *slow* (but simple) selection sort.
   *
   * @param names Array to hold the name of each contributor.
   * @param amt   Array to hold the name of each contributor.
   * @param n     The number of contributions stored in arrays.
  */
  public static void sort(String [] names, int [] amt, int n)
  {
    int i,j;          // counters
    int tamt;         // temporary amount (for swap)
    String tname;     // temprorary name (for swap)
    
    for (i=0; i<n-1; i++) 
      for (j=i+1; j<n; j++)
        if (amt[i] < amt[j]) {
          tamt= amt[i];
          amt[i]= amt[j];
          amt[j]= tamt;
          tname= names[i];
          names[i]= names[j];
          names[j]= tname;
        }
  }

}

