Hashing and Sorting

In this assignment you are to implement a hash function and use a Java sort through Java Utilities - they pretty much do it for you!

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeMap;

 Hashtable<String, Integer> hash = new Hashtable<>();
  1. Request name of input file from user
  2. Open the file
  3. Read a line of text
  4. Convert the text to all uppercase (String method)
  5. Replace everything except the letters A-Z with a space:
    "I-Can't!" becomes "I CAN T"
    	String[] words = read.nextLine().toUpperCase().replaceAll("[^A-Z]", " ").split(" ");
    	
  6. The spaces will now be assumed to delimit words
    Thus, T become a word rather than worry about single quotes versus apostrophes.
  7. Count each word by:
    • If it is not already in your hash table (hash.containsKey(words[i])), add it
      hash.put(words[i], 1)
    • Otherwise, add one to the number of times this word has been seen
      hash.put(words[index], (hash.get(words[index]))+1)
  8. Repeat to end of file
  9. Sort the hash table using a Java sort
    You can use a Java Treemap.
     TreeMap<String,Integer> treeMap = new TreeMap<String,Integer>(hash); //Use Tree Map on your hash table
    
    
  10. Using an iterator, print each word and the count of how many times it occurred, one per line in alphabetical order.
    Iterator itr = treeMap.keySet().iterator();
    while (itr.hasNext())
    {
       word = itr.next();
       //print word and treeMap's value
    }
    
Sample Data Sets:
Submission
Place your code in the D2L dropbox
Place a text document of your output for one of the datasets in the folder