title: Extending my program to report frequency of word in list and its line number?
body: <p>I've gotten my Java code below to this point. Now what I'm attempting to do is add to it so that it can report, for each word in the list, its frequency (number of times it exists) along with the line numbers where the word occurs.</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>// Concordance
  
  import java.util.*;
  
  // A concordance is a listing of words from a text, with each word being followed the line/page numbers on which the word appears. 
  
  public class Concordance 
  {
  
      private Dictionary dict = new Hashtable();
  
      private boolean allowDupl = true;
  
      public Concordance (boolean allowDupl ) 
      {
          this.allowDupl = allowDupl;
      } // end Concordance()
  
      public Concordance ( ) { this(true); }
  
      public void enterWord (Object word, Integer line) 
      {
          Vector set = (Vector) dict.get(word);
          if (set == null) // word not in dictionary
          {  
          set = new Vector( );
          dict.put(word, set);  // enter word and empty Vector
          } 
          if (allowDupl || !set.contains(line))
          { 
          set.addElement(line);
          }
      } // end enterWord()
  
      public Enumeration keys( ) 
      {
          return dict.keys( );
      } // end keys()
  
      public Enumeration getNumbers (Object word) 
      {
          return ((Vector)dict.get(word)).elements( );
      } // end getNumbers()
  
  } // end class Concordance
  </code></pre>
  
  <p>This is something I've been dabbling with, but Java is not at all my strong-language. Can anyone offer advice on how to proceed?</p>
  
  <p><em><strong>EDIT:</em></strong></p>
  
  <p>I've updated my code with the below. For those more familiar with Java, does this look correct?</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>// Concordance
  
  import java.util.*;
  
  // A concordance is a listing of words from a text, with each word being followed the line/page numbers on which the word appears. 
  
  public class Concordance 
  {
  
      private Dictionary dict = new Hashtable();
  
      private boolean allowDupl = true;
  
      public Concordance (boolean allowDupl ) 
      {
          this.allowDupl = allowDupl;
      } // end Concordance()
  
      public Concordance ( ) { this(true); }
  
      public void enterWord (Object word, Integer line) 
      {
          Vector set = (Vector) dict.get(word);
          if (set == null)  // word not in dictionary
          {
          set = new Vector( );
          dict.put(word, set);  // enter word and empty Vector
          } 
          if (allowDupl || !set.contains(line)) 
          {
          set.addElement(line);
          }
      } // end enterWord()
  
  
      public void generateOutput(PrintStream output) 
      {
          Enumeration e = dict.keys();
          while (e.hasMoreElements()) 
          {
              String word = (String) e.nextElement();
              Vector set = (Vector) dict.get(word);
              output.print(word + ": ");
              Enumeration f = set.elements();
          }
          while (f.hasMoreElements())
          {
              output.print(f.nextElement() + " ");
              output.println("");
          }
      }
  
      public Enumeration keys( ) 
      {
          return dict.keys( );
      } // end keys()
  
      public Enumeration getNumbers (Object word) 
      {
          return ((Vector)dict.get(word)).elements( );
      } // end getNumbers()
  
  } // end class Concordance
  </code></pre>