Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Build a tree of BinaryNodes that represents the Morse Code tree shown here.
- blank
- |
- -------------------------
- / \
- / \
- / \
- E T
- | |
- --------- --------
- / \ / \
- / \ / \
- I A N M
- / \ / \ / \ / \
- S U R W D K G O
- / \ / / / \ / \ / \ / \
- H V F L P J B X C Y Z Q
- Use Weiss's BinaryNode class (see Resources).
- Here is the skeleton for the class you are to implement.
- /** MorseCodeTree is a binary tree representation of Morse Code.
- * The tree can be used to decode a sentence of Morse code symbols.
- * @author J. Dalbey
- * @version 10/2009
- */
- public class MorseCodeTree
- {
- private static BinaryNode<Character> bt = new BinaryNode<Character>();
- /* Constant for a blank character */
- private static final char kBlank = ' ';
- /** Convert a morse code message to plain english text.
- * The morse code text is sequences of dots (periods), and dashes, separated by blank spaces.
- * At least one blank character must separate each "letter group" (1 to 4 symbols).
- * Extraneous blanks (i.e., more than one) between "letters" are echoed to the output.
- * Blanks at the beginning or at the end are ignored.
- * Any non-alphabetic characters are ignored.
- * @param morseText a string of morse code symbols
- * @return String of the decoded english text.
- */
- public static String decode(String morseText)
- {
- }
- /** A static method for debugging the tree structure */
- public static void debug()
- {
- System.out.println(BinaryNode.height(bt));
- System.out.println(BinaryNode.size(bt));
- bt.printInOrder();
- }
- }
- You should build the binary tree in a static initializer block.
- Do not create a constructor.
- http://imgur.com/5NqP53S.png
- Here's a sample JUnit assert:
- assertEquals("LIONS TIGERS",MorseCodeTree.decode(".-.. .. --- -. ... - .. --. . .-. ..."));
- Put both author's names in separate @author tags. Submit your MorseCodeTree and BinaryNode classes to Web-CAT.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement