Lab 8
Get started now
## Overview In this lab, you write and test two classes: `MorseEncoder` and `LookupTable`. ## 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 to store Morse Code table. The lookup table must implement the [`Map<K, V>`](http://javadoc.taylorial.com/java.base/util/Map.html) 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 `LookupTable` class must include implementations of the following methods (the remaining methods may throw an `UnsupportedOperationException`). * [**`clear()`**](http://javadoc.taylorial.com/java.base/util/Map.html#clear%28%29) * [**`containsKey(Object key)`**](http://javadoc.taylorial.com/java.base/util/Map.html#containsKey%28java.lang.Object%29) * [**`get(Object key)`**](http://javadoc.taylorial.com/java.base/util/Map.html#get%28java.lang.Object%29) * [**`isEmpty()`**](http://javadoc.taylorial.com/java.base/util/Map.html#isEmpty%28%29) * [**`put(K key, V value)`**](http://javadoc.taylorial.com/java.base/util/Map.html#put%28K,V%29) * [**`remove(Object key)`**](http://javadoc.taylorial.com/java.base/util/Map.html#remove%28java.lang.Object%29) * [**`size()`**](http://javadoc.taylorial.com/java.base/util/Map.html#size%28%29) Your program should be implemented in the `MorseEncoder` class. The design for this class is your responsibility. The `LookupTable` will consist of a sorted list of key/value mappings. For example, one element in the table will store a mapping from <kbd>`A`</kbd> (the key) to <kbd>`.-`</kbd> (the value); Another element will store a mapping from <kbd>`B`</kbd> (the key) to <kbd>`-...`</kbd> (the value); Etc... The elements in the table will be sorted based on the keys. E.g., <kbd>`A`</kbd>, <kbd>`B`</kbd>, etc... In particular, your `LookupTable` class must use a `List<Map.Entry<K extends Comparable<? super K>, V>>` to store the morse code table. Each `Entry` should hold a key/value pair. The entries must be stored in sorted order based on the keys (you may not use the `SortedArrayList` class). Since you are maintaining a sorted list of `Entry` objects, your `Entry` class must implement the `Comparable<Entry<K, V>>` interface. A number of methods require the use of the [`Collections.binarySearch()`](http://javadoc.taylorial.com/java.base/util/Collections.html#binarySearch%28java.util.List,T%29) 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: * The Morse code table should be read in from the `morsecode.txt` file ([download](morsecode.txt)). * 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. * You should not call `.sort()`. If you are tempted to do so, get help! ## Sample Results Running your program on this file: <pre> 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. </pre> should display something like this to the console: <pre> 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: * </pre> and produce the following output file: <pre> .- .-... ... .--. .- -.-. . .-... ... .... --- ..- .-.. -.. .-... -... . .-... .--. .-.. .- -.-. . -.. .-... -... . - .-- . . -. .-... . .- -.-. .... .-... . -. -.-. --- -.. . -.. .-... -.-. .... .- .-. .- -.-. - . .-. .-.-.- .-.- .-.- .- .-... .-... .-... ... .... --- ..- .-.. -.. .-... -... . .-... .--. .-.. .- -.-. . -.. .-... -... . - .-- . . -. .-... . .- -.-. .... .-... .-- --- .-. -.. .-.-.- .-.- .-.- .-.. .. -. . .-... -... .-. . .- -.- ... .-... .. -. .-... - .... . .-... .. -. .--. ..- - .-... ..-. .. .-.. . .-... ... .... --- ..- .-.. -.. .-... -... . .-... .-. . .--. .-.. .. -.-. .- - . -.. .-... .. -. .-... - .... . .-... . -. -.-. --- -.. . -.. .-... ..-. .. .-.. . .-.-.- .-.- </pre> ## Lab Deliverables > See your professor's instructions for details on submission guidelines and due dates. > * Dr. Taylor's students: See below > * All other students should refer to Blackboard > >If you have any questions, consult your instructor. ## Acknowledgements This assignment was developed by [Dr. Jay Urbain](http://jayurbain.com/msoe/) and [Dr. Chris Taylor](/taylor/).

Friday, 26-Apr-2019 06:59:47 EDT