/**
 * Problem states that there are exactly 10 salespeople. We will read in this
 * data from a file called salespeople.txt
 * CarDealer2 MODIFIES THE CARDEALER PGM TO USE PARTIALLY POPULATED ARRAYS.
 */
import java.io.*;
import java.util.Scanner;

public class CarDealer2 {
  
  public static void main(String[] args) throws IOException {
   
    String filename = "salespeople.txt";
    // File file = new File(filename);
    Scanner infile = new Scanner(new File(filename));
    final int SIZE = 100;
    String[] names = new String[SIZE];
    int[] carsSold = new int[SIZE];
    int size = populateArrays(infile, names, carsSold);
    printArrays(names, carsSold, size);
    // 1. total
    System.out.println("sum of all cars sold is: " + sum(carsSold, size));
    // 2. max
    int index = maximum(carsSold, size);
    for (int i=0; i<carsSold.length; i++)
      if (carsSold[i] == carsSold[index]) // carsSold[index] is the max
       System.out.println(names[i] + " sold the most cars: " + carsSold[i]);
    // 3. check array carsSold for duplicates
    if (hasDuplicates(carsSold, size))
      System.out.println("yes, array has duplicates.");
    else
      System.out.println("no, array has NO duplicates.");
  }
  /*
   * @return number of data elements read in
   */
  public static int populateArrays(Scanner sc, String[] pple, int[] nums) {
    int count=0;
    // make sure that I don't overrun my arrays even if file has lots of data
    while (sc.hasNext() && count < pple.length) {
      pple[count] = sc.next();
      nums[count] = sc.nextInt();
      count++;
    }
    return count;
  }
  public static void printArrays(String[] pple, int[] nums, int n) {
    
    for (int i=0; i<n; i++) {
      System.out.println(i + ": " + pple[i] + "  " + nums[i]);
    }
  }
  // 1. calculate total number of cars sold
  public static int sum(int[] nums, int n)  {
    int sum=0;
    for (int i=0;i<n;i++)
      sum+=nums[i];
    return sum;
  }
  // 2. find max index so we can print name and number in main
  public static int maximum(int[] nums, int n) {
    int maxi=0;  // nums[0] is initial value for max
    for (int i=1;i<n;i++)
        if (nums[maxi] < nums[i])
            maxi=i;
    return maxi;
  }
  public static boolean hasDuplicates(int[] nums, int n) {
   // fill in code 
    return true;
  }
    
  
}