weight = 18

Lab 8: Morse Code Encoder

Learning Outcomes

Overview

In this lab, you are going to implement a program that encodes messages written in morse code. You will use a map (that you will implement) to look up the morse code associated with each English character.

Your program should be run from the command line and be given the input and output filenames. (The data/codeword.txt file can be hardcoded.)

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:

If your program encounters any characters not found in the map (e.g., '), it should report an error message to the console, skip the character, and continue on.
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: *

and produce the following output file:

.- .-... ... .--. .- -.-. . .-... ... .... --- ..- .-.. -.. .-... -... . .-... .--. .-.. .- -.-. . -.. .-... -... . - .-- . . -. .-... . .- -.-. .... .-... . -. -.-. --- -.. . -.. .-... -.-. .... .- .-. .- -.-. - . .-. .-.-.- .-.-
.-.-
.- .-... .-... .-... ... .... --- ..- .-.. -.. .-... -... . .-... .--. .-.. .- -.-. . -.. .-... -... . - .-- . . -. .-... . .- -.-. .... .-... .-- --- .-. -.. .-.-.- .-.-
.-.-
.-.. .. -. . .-... -... .-. . .- -.- ... .-... .. -. .-... - .... . .-... .. -. .--. ..- - .-... ..-. .. .-.. . .-... ... .... --- ..- .-.. -.. .-... -... . .-... .-. . .--. .-.. .. -.-. .- - . -.. .-... .. -. .-... - .... . .-... . -. -.-. --- -.. . -.. .-... ..-. .. .-.. . .-.-.- .-.-

Implementation

In this lab, you write and test three classes: MorseDriver, MorseEncoder, and HashMap.

MorseDriver

Your MorseDriver class must have a main method that accepts the two filenames as command line input. See SLM 7. The design of remainder of this class is your responsibility.

MorseEncoder

Your MorseEncoder class must contain the following two methods:

HashMap

Your HashMap class must implement the Map<K, V> interface to store 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. Your implementation of the HashMap class must include implementations of the following methods (the remaining methods may throw an UnsupportedOperationException).

The HashMap will consist of a set of HashMapEntry objects that map the key (character) to the corresponding symbol (Morse code). For example, one element in the table will store a mapping from A (the key) to .- (the value); Another element will store a mapping from B (the key) to -... (the value); Etc... The elements in the table will be sorted based on the keys. E.g., A, B, etc...

Your HashMap class should have an array of length 1024 for the hash table. You should handle collisions using chaining. Every element of the array should be a list of Map.Entry<K, V> references. You can use the hash code of the key to determine the array index and store the entry in the associated list. Multiple keys may map to the same array index but keys may not be duplicated. You should not worry about tracking the collision rate or resizing the array.

Additional details:

See your professor's instructions for details on submission guidelines and due dates.

Acknowledgements

This assignment was developed by Dr. Jay Urbain, Dr. Chris Taylor, and Dr. RJ Nowling.