Turn in assignment as both a hardcopy in class and a zipped file, using this link to cardea. Please have all your code as runnable .java files.
The purpose of this assignment is to give you practice in choosing and using standard data structures.
You are doing some consulting work for the CIA. They are intercepting coded messages and need your help in decoding them.
Every pair of words is a code for a single English word. Your job is to write program to translate the code words into readable English. If you get a pair of words that doesn't have a known corresponding translation, print out "UNKNOWN" or "-----" or something similar.
(A) What is the appropriate data structure for this code? Why?
(B) Write translation code that takes code as input and produces readable English as output.
I've also started the code for you; it has all the method definitions as well as a method for switching between translating code to English and converting English into code.
To process this code you might want to draw inspiration from the code to read in and tokenize an input file, buildTreeFromFile from FullTree.java.
Notes: When your code is working it will take a while to process the input file unless you are on a very fast machine. Also, if you are using textpad, the code I wrote for accepting input doesn't work if you have "capture output" set under Preferences. You have to turn this feature off.
Test your code on these input strings:
Code 2: pacify presto incentive fir pink tragicomic Sterno chignon Bengali Willis lew renegotiable
Code 3: greengrocer Caspian corridor riotous incentive fir Lucia eyelet
Code 4: Sterno chignon debauchery campsite Bombay museum rectory nightfall dilatory Juneau
(C) It would have been a lot of work for me to make up these coded messages accurately, but I wrote some java code that made it easy for me to do so. Write a method codeSentence that essentially does the opposite of what you wrote for part (B).
(D) It would have been a lot of work for me to create the codes by hand. First I would have had to think of lots and lots of code words, and second, I have to avoid repeats. I wrote a program to automate this; have a try at writing it yourself.