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

class HW17_MAP {
  private HashMap<String, Integer> map;
  
  public HW17_MAP( String filename ) {
    map = new HashMap<String,Integer>();
    doReadFromFile( filename );
  }
  
  private void doReadFromFile( String filename ) {
    // make a Scanner tied to the file
    Scanner scanner = null;
    try {
      scanner = new Scanner( new File( filename ) );
    } catch ( java.io.FileNotFoundException e ) {
      System.out.println( "Couldn't open " + filename );
      System.exit(-1);  // terminate the program
    }
    
    // build the map
    while ( scanner.hasNext() ) {
      updateMap( scanner.next() );
    }
  }

  private void updateMap( String term ) {
    term = term.toLowerCase();

    Integer count = map.get( term );
    if ( count == null )
      map.put( term, 1 );
    else
      map.put( term, (count + 1) );

    return; // not in the map of known words
  }
  
  public int uniqueWordCount() {
    return map.size();
  }
  
  public void printWordStats() {
    // read the HashMap JavaDocs and figure out if this is possible
    // and how to do it if it is...
  }

  public static void main( String[] arg ) {
    new HW17( "HW17_MAP.java" ).printWordStats();
  }
} // end class HW17_MAP  

