Lab 11: Morse Code Encoder

Learning Outcomes

Overview

Video 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's GUI will appear similar to the one from lab 9, however we will be implementing menus in place of buttons to select actions.

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 the following in an Alert after encoding:

Warning: skipping: *
Warning: skipping: *
Warning: skipping: '
Warning: skipping: '
Warning: skipping: '
Warning: skipping: '
Warning: skipping: *
Warning: skipping: *

and produce the following output:

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

Implementation

In this lab, in addition to your MorseDriver class that will launch your GUI, you write and test three classes: MorseEncoder, HashMap, and your Controller class.

MorseEncoder

Your MorseEncoder class must contain the following three methods:

The MorseEncoder class will also contain a HashMapcalled MAP that will store the morse code information.

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 must have an array of length 1024 for the hash table and be called entries. You must handle collisions using chaining. Every element of the array must 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.

Controller

Your Controller class will need to implement the Initializable interface and define at mimimmum the following functionality

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, Dr. RJ Nowling, and Prof. Sean Jones.