Overview
Morse Code is a method for communicating using two symbols: dots and dashes. In this lab, you write and test two classes: MorseEncoder
and LookupTable
.
Each character has a code, consisting of zero or more dots and zero or more dashes. The following table describes the mapping for many popular characters:
A | .- | K | -.- | U | ..- | 4 | ....- |
---|---|---|---|---|---|---|---|
B | -... | L | .-.. | V | ...- | 5 | ..... |
C | -.-. | M | -- | W | .-- | 6 | -.... |
D | -.. | N | -. | X | -..- | 7 | --... |
E | . | O | --- | Y | -.-- | 8 | ---.. |
F | ..-. | P | .--. | Z | --.. | 9 | ----. |
G | --. | Q | --.- | 0 | ----- | . | .-.-.- |
H | .... | R | .-. | 1 | .---- | , | --..-- |
I | .. | S | ... | 2 | ..--- | / | -..-. |
J | .--- | T | - | 3 | ...-- | ? | ..--.. |
Procedure
Your program must read in a file and produce an encoded version (using Morse Code) of that file (written to an output file). Your program must make use of the LookupTable
class (download) to store Morse Code table. The lookup table stores each code in a key/value pair where the key is the character to be encoded and the value is the code associated with the key. A UML class diagram of the LookupTable
class is shown below. You must complete the implementation of the LookupTable
class. Your program should be implemented in the MorseEncoder
class. The design for this class is your responsibility.
The Entry
class is an inner class of the LookupTable
class and is used to keep track of the key/value pairs. Be sure to study the javadoc comments within the LookupTable.java
file in order to complete the implementation of each method correctly. A number of methods require the use of the Collections.binarySearch() method in order to find the location of the entry in the lookup table. Note that since the LookupTable
class has a list of Entry
objects in it, you'll need to pass an Entry
object to binary search. This Entry
object can have a value attribute of null
.
Additional details:
- You are required to implement insertion sort to maintain the sorted order of your
LookupTable
. - The Morse code table should be read in from the
morsecode.txt
file (download). - Your program should convert all characters to uppercase before looking up the corresponding Morse code.
- Your program should not encode characters that are not found in the lookup table. A warning message should be displayed to the console for any character encountered that is not in the Morse code table.
- A space should be placed between each encoded character.
- A
|
should be placed between each word. - Line breaks in the input file should be replicated in the encoded file.
- If you are tempted to call
.sort()
, get help!
Sample Results
Running your program on this file:
A space should be placed between each encoded character.
A **''|''**
should be placed between each word.
Line breaks in the input file should be replicated in the encoded file.
should display something like this to the console:
Enter an input filename: input.txt Enter an output filename encoded.txt Warning: skipping: * Warning: skipping: * Warning: skipping: ' Warning: skipping: ' Warning: skipping: | Warning: skipping: ' Warning: skipping: ' Warning: skipping: * Warning: skipping: *
and produce the following output file:
.- | ... .--. .- -.-. . | ... .... --- ..- .-.. -.. | -... . | .--. .-.. .- -.-. . -.. | -... . - .-- . . -. | . .- -.-. .... | . -. -.-. --- -.. . -.. | -.-. .... .- .-. .- -.-. - . .-. .-.-.- | .- | | ... .... --- ..- .-.. -.. | -... . | .--. .-.. .- -.-. . -.. | -... . - .-- . . -. | . .- -.-. .... | .-- --- .-. -.. .-.-.- | .-.. .. -. . | -... .-. . .- -.- ... | .. -. | - .... . | .. -. .--. ..- - | ..-. .. .-.. . | ... .... --- ..- .-.. -.. | -... . | .-. . .--. .-.. .. -.-. .- - . -.. | .. -. | - .... . | . -. -.-. --- -.. . -.. | ..-. .. .-.. . .-.-.- |
Acknowledgements
This assignment was written by Dr. Jay Urbain.
Lab Deliverables
Dr. Taylor's class: See below
Dr. Yoder's submission instructions