Question: Concepts tested by this program: Generic Classes Utility Class (all static methods) New concepts tested by this program: Linked Trees Building a Tree for conversion

Concepts tested by this program:

Generic Classes

Utility Class (all static methods)

New concepts tested by this program:

Linked Trees

Building a Tree for conversion purposes

Samuel F. B. Morse produced the first working telegraph set in 1836. This made transmission possible over any distance. The first Morse Code message, "What hath God wrought?", was sent from Washington to Baltimore.

Morse code was extensively used for early radio communication beginning in the 1890s.

In the early part of the twentieth century, the majority of high-speed international communication was conducted in Morse code, using telegraph lines, undersea cables, and radio circuits.

Morse code can also be transmitted using light which sometimes happens between ships at sea. It is used in emergencies to transmit distress signals when no other form of communication is available. The standard international distress signal is --- (SOS).

Your assignment is to write a generic TreeNode class, a MorseCodeTree class and a MorseCodeConverter class. There is no GUI required for this assignment. Your classes will be tested with Junit tests.

TreeNode class

This generic class is used in the MorseCodeTree classes. The class consists of a reference to the data and a reference to the left and right child. Follow the Javadoc that is provided. The Javadoc only lists those public methods that are required to pass the Junit tests. You may add any private methods you need for your design.

MorseCodeTree class

A generic linked binary tree which inherits from the LinkedConverterTreeInterface. The class uses an external generic TreeNode class parameterized as a String: TreeNode. This class uses the private member of root. Nodes are added based on their morse code value. A . (dot) means to traverse left and a - (dash) means to traverse right. The constructor will build the tree. Follow the Javadoc that is provided. The Javadoc only lists those public methods that are required to pass the Junit tests. You may add any private methods you need for your design.

Building the Data Structure (buildTree)

Your MorseCodeTree is a tree 4 levels. Insert a mapping for every letter of the alphabet into the tree map. The root is a TreeNode with an empty string. The left node at level 1 stores letter e (code .) and the right node stores letter t (code -). The 4 nodes at level 2 are i, a, n, m (code .., .-, -., ). Insert into the tree by tree level from left to right. A . will take the branch to the left and a - will take the branch to the right. This is the structure of the tree.

Using the Data Structure

Use the MorseCodeTree to convert Morse Code to English by taking the code and finding its corresponding English letter by traversing the MorseCodeTree, . branches to the left and - branches to the right. The code .--. would branch to the left, then to the right, then to the right, then to the left to Fetch the letter p. Each letter is delimited by a space ( ). Each word is delimited by a /.

MorseCodeConverter Utility Class

The MorseCodeConverter contains a static MorseCodeTree object and constructs (calls the constructor for) the MorseCodeTree.

This class has two static methods convertToEnglish to convert from morse code to English. One method is passed a string object (.-.. --- ...- . / .-.. --- --- -.- ...). The other method is passed a file to be converted. These static methods use the MorseCodeTree to convert from morse code to English characters. Each method returns a string object of English characters.

There is also a static printTree method that is used for testing purposes to make sure the tree for MorseCodeTree was built properly.

Use the Javadoc provided to make sure that your MorseCodeConverter class follows the method headers so that the MorseCodeConverterTest will run correctly.

The JUnit Test Class

You must add at least 1 test for MorseCodeConverter.convertToEnglish(String) and at least 1 test for MorseCodeConverter.convertToEnglish(File) to the MorseCodeConverterTest class. Include your test file with your code files.

Test Cases:

Hello World

How do I love thee let me count the ways

Some suggestions:

1. There is a morse code translator at:

http://morsecode.scphillips.com/jtranslator.html

it will help you make test cases

----------------------------------------------------------------------------------------------------------------------------------------------------

public interface LinkedConverterTreeInterface { /** * Returns a reference to the root * @return reference to root */ public TreeNode getRoot(); /** * sets the root of the Tree * @param newNode a TreeNode that will be the new root */ public void setRoot(TreeNode newNode); /** * Adds result to the correct position in the tree based on the code * This method will call the recursive method addNode * * @param code the code for the new node to be added * @return the linkedConverterTree with the new node added */ public LinkedConverterTreeInterface insert(T code, T result); /** * This is a recursive method that adds element to the correct position * in the tree based on the code. * * @param root the root of the tree for this particular recursive instance of addNode * @param code the code for this particular recursive instance of addNode * @param letter the data of the new TreeNode to be added */ public void addNode(TreeNode root, T code, T letter); /** * Fetch the data in the tree based on the code * This method will call the recursive method fetchNode * * @param code the code that describes the traversals within the tree * @return the result that corresponds to the code */ public T fetch(String code); /** * This is the recursive method that fetches the data of the TreeNode * that corresponds with the code * * @param root the root of the tree for this particular recursive instance of addNode * @param code the code for this particular recursive instance of fetchNode * @return the data corresponding to the code */ public T fetchNode(TreeNode root, T code); /** * This operation is not supported for a LinkedConverterTree * @param data data of node to be deleted * @return reference to the current tree * @throws UnsupportedOperationException */ public LinkedConverterTreeInterface delete(T data) throws UnsupportedOperationException; /** * This operation is not supported for a LinkedConverterTree * @return reference to the current tree * @throws UnsupportedOperationException */ public LinkedConverterTreeInterface update() throws UnsupportedOperationException; /** * This method builds the LinkedConverterTree by inserting TreeNodes * into their proper locations * */ public void buildTree(); /** * Returns an ArrayList of the items in the linked converter Tree in LNR (Inorder) Traversal order * Used for testing to make sure tree is built correctly * @return an ArrayList of the items in the linked Tree */ public ArrayList toArrayList(); /** * The recursive method to put the contents of the linked converter tree in an ArrayList * LNR (Inorder) * @param root the root of the tree for this particular recursive instance * @param list the ArrayList that will hold the contents of the tree in LNR order */ public void LNRoutputTraversal(TreeNode root, ArrayList list); } 

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!