// import cs201j.*; - cut for now because of problem with ITC file locations
import java.io.*;

public class AverageLength {
   public static void main (/*@non_null@*/ String args[]) throws RuntimeException
    {
        String filename = args[0];
        
        try {
            FileInputStream infile = new FileInputStream (filename);
            StringTable names = new StringTable (infile);
            int numnames = names.size ();
            int totallength = 0;
            
            // Calculate the average length of all the names in the file.
            
            for (int index = 0; index <= numnames; index++) {
                String name = names.getNthLowest (index);
                totallength = totallength + name.length ();
            }
            
            System.out.println ("The average name length is: " 
                                + (double) totallength / numnames); 
            // The double cast is necessary to produce a precise (non-integer result)
        } catch (FileNotFoundException e) {
            System.err.println ("Cannot fine file: " + filename);
            System.exit (1);
        }
    }
}
