Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 datasubdirectory 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

Database Design And Implementation

Authors: Shouhong Wang, Hai Wang

1st Edition

1612330150, 978-1612330150

More Books

Students also viewed these Databases questions

Question

1. What steps might you include or remove from this process?

Answered: 1 week ago