FrequencyList File import javaio import javautil import ch08
FrequencyList File:
import java.io.*;
 import java.util.*;
 import ch08.trees.*;
 import ch08.wordFreqs.*;
public class FrequencyList
 {
 public static void main(String[] args) throws IOException
 {
 String word;
 WordFreq wordToTry;
 WordFreq wordInTree;
 WordFreq wordFromTree;
BinarySearchTree<WordFreq> tree = new BinarySearchTree<WordFreq>();
 String skip; // skip end of line after reading integer
int numWords = 0;
 int numValidWords = 0;
 int numValidFreqs = 0;
 int minSize;
 int minFreq;
 int treeSize;
// Set up file reading
 FileReader fin = new FileReader(\"words.dat\");
 Scanner wordsIn = new Scanner(fin);
 wordsIn.useDelimiter(\"[^a-zA-Z0-9]\"); // delimiters are nonletters-digits
// Set up console reading
 Scanner conIn = new Scanner(System.in);
//Get word and frequency limits from user
 System.out.print(\"Minimum word size: \");
 minSize = conIn.nextInt();
 skip = conIn.nextLine();
 System.out.print(\"Minimum word frequency: \");
 minFreq = conIn.nextInt();
 skip = conIn.nextLine();
while (wordsIn.hasNext()) // while more words to process
 {
 word = wordsIn.next();
 numWords++;
 if (word.length() >= minSize)
 {
 numValidWords++;
 word = word.toLowerCase();
 wordToTry = new WordFreq(word);
 wordInTree = tree.get(wordToTry);
 if (wordInTree == null)
 {
 // insert new word into tree
 wordToTry.inc(); // set frequency to 1
 tree.add(wordToTry);
 }
 else
 {
 // word already in tree, just increment frequency
 wordInTree.inc();
 }
 }
 }
   
 treeSize = tree.reset(BinarySearchTree.INORDER);
 System.out.println(\"The words of length \" + minSize + \" and above,\");
 System.out.println(\"with frequency counts of \" + minFreq + \" and above:\");
 System.out.println();
 System.out.println(\"Freq Word\");
 System.out.println(\"----- -----------------\");
 for (int count = 1; count <= treeSize; count++)
 {
 wordFromTree = tree.getNext(BinarySearchTree.INORDER);
 if (wordFromTree.freqIs() >= minFreq)
 {
 numValidFreqs++;
 System.out.println(wordFromTree);
 }
 }
System.out.println();
 System.out.println(numWords + \" words in the input file. \");
 System.out.println(numValidWords + \" of them are at least \" + minSize + \" characters.\");
 System.out.println(numValidFreqs + \" of these occur at least \" + minFreq + \" times.\");
 System.out.println(\"Program completed.\");
 }
 }
Solution
 1.
    useDelimiter() methods are used to tokenize the Scanner input,
    With Scanner the default delimiters are the whitespace characters.
    So, if you remove \'useDelimiter()\', then Scanner tokenize input string by space.
2.
    So, if you remove toLowerCase method, then \'\'xYz\' and \'XYz\' will be two different element for BinarySearchTree
    Hence elements in BinarySearchTree will be case sensitive
3.
    replacing toLowerCase method with toUpper will not affect the frequency of words.
4.
    if you call wordInTree.inc() with wordToTry.inc(), then all the words will have frequency 1


