] > Assignment 6: Inverse a Dictionary (Due: Th, Nov 13)

Assignment 6: Inverse a Dictionary (Due: Th, Nov 13)

Write a program Dict.java that prints an Indian Alaska to English dictionary, by inversing the English to Indian Alaskan dictionary available at http://www.gutenberg.org/files/10040/10040.txt.

Notes.

Suggestion. Build your program incrementally in the following manner.

  1. Provide a program that reads the given file from the web and prints it out.
  2. Modify the program to print out just the lines that contain the substring "...".
  3. Extract the English and the Indian Alaska parts of each line by breaking the line at the first occurrence of the substring "...". Print the pairs of English and Indian Alaska parts, instead of the whole input lines.
  4. Remove the leading dots from the Indian Alaska.
  5. Store the pairs of the English and Indian Alaska parts in a hash map, using the Indians Alaska parts as keys.
  6. Upon completion of reading the input file, extract the keys from hash map with a command similar to

    String [] key = dict.keySet().toArray(new String[0])

    and print the array. (The variable ‘dict’ is assumed to hold the hash table created in the previous step.)

  7. Sort the array of keys before printing its values.
  8. Print with each key its corresponding value from the hash map. The trailing portion of the out should be similar to the following segment.

    Wa-gak...........Wind, S.W  
    Wa-shak...........Wind, N.E  
    Wai...........There, right, here  
    Wai, also ma-na...........Here  
    Wia...........Right, here, there  
    Win-gee...........Me, I  
    Wodka...........Whiskey (Russian)

Problems.

  1. In old versions of Java, use constructs of the forms

    HashMap dic = new HashMap()
    String [] key = (String []) dict.keySet().toArray(new String[0])

    instead of constructs of the following forms.

    HashMap<String, String> dic = new HashMap<String, String>()
    String [] key = dict.keySet().toArray(new String[0])

  2. The version in use of Java can be found with the command ‘java -version’.