Question: MORSE CODE FILE: A *- B -*** C -*-* D -** E * F **-* G --* H **** I ** J *--- K -*-

MORSE CODE FILE:

A *- B -*** C -*-* D -** E * F **-* G --* H **** I ** J *--- K -*- L *-** M -- N -* O --- P *--* Q --*- R *-* S *** T - U **- V ***- W *-- X -**- Y -*-- Z --** 0 ----- 1 *---- 2 **--- 3 ***-- 4 ****- 5 ***** 6 -**** 7 --*** 8 ---** 9 ----* . *-*-*- , --**-- ? **--** ! -*-*-- ( -*--* ) -*--*- : ---*** ; -*-*-* @ *--*-*

TREE NODE INTERFACE

package edu.metrostate.ics240.p5.morse;

public interface TreeNode { TreeNode getLeftChild(); TreeNode getRightChild(); T getValue(); }

You have been asked to write a Morse Code Encoder/Decoder.

Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks that can be directly understood by a skilled listener or observer without special equipment. It is named for Samuel F. B. Morse, an inventor of the telegraph. The International Morse Code encodes the ISO basic Latin alphabet, some extra Latin letters, the Arabic numerals and a small set of punctuation and procedural signals (prosigns) as standardized sequences of short and long signals called "dots" and "dashes", or "dits" and "dahs", as in amateur radio practice. (Wikipedia)

Assignment

Create a MorseCode class as described below:

Signature Requirement
Constructors
N/A This is a utility class that has only static members. Since no objects will be instantiated any initialization must be done in static initializer blocks. No constructors will be activated. If you choose to load the morseCode.txt file it must be fully contained and accessible from your solution from a foreign machine. Suggested approach: place data file in a data subdirectory in your solution package and access using the getResourceAsStream() method
Methods
public static String encode(String text) Translates the given text of ASCII Latin Characters to its morse code equivalent. The encoding places a space between encoded characters; a space in the text is represented as a SLASH ('/') character. The text can be in mixed case.

Preconditions

The text string cannot be null. If so, the method will throw a NullPointerException

The text contains only the subset of characters contained in the provided morseCode.txt file and spaces.

If an unrecognized character is encountered, the method should throw an IllegalArgumentException with text indicating the invalid character.

Note:the class must be reentrant, that is, it must be possible for multiple threads to call the encode and decode methods simultaneously. To ensure this one cannot use store working data in class member variables since all threads will try to share the same variables

public static String decode(String code) Decodes the provided code string to its text representation. Since Morse Code is case-less, the returned string will be in all UPPER CASE characters.

Preconditions

The code string cannot be null. If so, the method will throw a NullPointerException

The code string contains only DOTs ('*'), DASHes('-'), spaces that separate characters, and SLASHes('/') that represent spaces in the original text.

If an unrecognized code is encountered, the method should throw an IllegalArgumentException with text displaying the decoded text up to the invalid code and the unrecognized code.

Note:the class must be reentrant, that is, it must be possible for multiple threads to call the encode and decode methods simultaneously. To ensure this one cannot use store working data in class member variables since all threads will try to share the same variables

Note: your solution must traverse the decodingTree when decoding.

public static Map getEncodingMap() Returns the mapping of encodings from each character to its morse code representation.
public static TreeNode getDecodingTree() Returns the root node of the binary tree used to decode a code string containing DOTs, DASHes, SLASHes, and space characters to its character representation

To ensure consistency, the right children represent DOTs, the left children DASHes.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!