Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions

Question

Explain in detail how the Mughal Empire was established in India

Answered: 1 week ago