/**
 * Contribution Tracking
 *
 * @author  Terry Sergeant
 * @version 01 Apr 2008
 *
*/

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

public class ContributionsStart
{
  public static void main(String [] args) throws FileNotFoundException
  {
    Scanner kb= new Scanner(System.in);
    String [] names;            // names of the contributors
    int [] candidates;          // code (1 to 10) identifying the candidate receiving the contribution
    int [] amounts;             // the amounts of the contributions
    int numberOfEntries;        // number of elements in the arrays
    int i;                      // loop counter

    names= new String[100000];
    candidates= new int[100000];
    amounts= new int[100000];

    numberOfEntries= readDataFile(names,candidates,amounts);

    System.out.println("There are currently "+numberOfEntries+" names/numbers");
    System.out.println("The first 10 entries are: ");
    for (i=0; i<10; i++)
      System.out.println(amounts[i]+" "+candidates[i]+" "+names[i]);

    System.out.println("\nThe last 10 names are: ");
    for (i=numberOfEntries-10; i<numberOfEntries; i++)
      System.out.println(amounts[i]+" "+candidates[i]+" "+names[i]);
  }

  /**
   * Reads contribution data from file into the appropriate arrays.
   *
   * @param names    An array of names to be loaded with data from the file
   * @param candidates An array of candidate codes that identify which
   *        candidate the contribution belongs to
   * @param amounts An array of dollar amounts (no cents) of contribution amounts
   * @return the number of name/phone pairs loaded into the arrays
  */
  public static int readDataFile(String [] names, int [] candidates, int [] amounts) throws FileNotFoundException
  {
    Scanner data= new Scanner(new File("contributions.txt"));
    int n;  // number of elements in the data file

    n= 0;
    while (data.hasNextLine())
    {
      amounts[n]= data.nextInt();
      candidates[n]= data.nextInt();
      names[n]= data.nextLine().trim();  // read and then chop off leading space
      n= n + 1;
    }
    return n;
  }
}

