Advertisement
jdalbey

Morse Code Tree Lab

Feb 23rd, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1. Build a tree of BinaryNodes that represents the Morse Code tree shown here.
  2.  
  3.                                    blank              
  4.                                      |                  
  5.                          -------------------------      
  6.                        /                            \      
  7.                      /                                \    
  8.                    /                                    \    
  9.                  E                                       T        
  10.                  |                                       |        
  11.              ---------                               --------      
  12.           /             \                         /           \    
  13.         /                 \                     /               \      
  14.        I                   A                   N                 M  
  15.    /       \           /      \            /       \           /   \
  16.   S         U         R        W          D         K         G     O
  17.  / \       /         /        / \        / \       / \       / \  
  18. H   V     F         L         P   J     B   X     C   Y     Z   Q
  19.  
  20. Use Weiss's BinaryNode class (see Resources).
  21.  
  22. Here is the skeleton for the class you are to implement.
  23.  
  24. /** MorseCodeTree is a binary tree representation of Morse Code.
  25. * The tree can be used to decode a sentence of Morse code symbols.
  26. * @author J. Dalbey
  27. * @version 10/2009
  28. */
  29. public class MorseCodeTree
  30. {
  31.    private static BinaryNode<Character> bt = new BinaryNode<Character>();
  32.    /* Constant for a blank character */
  33.    private static final char kBlank = ' ';
  34.      
  35.    /**  Convert a morse code message to plain english text.
  36.      * The morse code text is sequences of dots (periods), and dashes, separated by blank spaces.
  37.      *  At least one blank character must separate each "letter group" (1 to 4 symbols).
  38.      * Extraneous blanks (i.e., more than one) between "letters" are echoed to the output.
  39.      * Blanks at the beginning or at the end are ignored.
  40.      * Any non-alphabetic characters are ignored.
  41.      * @param morseText a string of morse code symbols
  42.      * @return String of the decoded english text.
  43.    */
  44.    public static String decode(String morseText)
  45.    {
  46.    }
  47.  
  48.    /** A static method for debugging the tree structure */
  49.    public static void debug()
  50.    {
  51.        System.out.println(BinaryNode.height(bt));  
  52.        System.out.println(BinaryNode.size(bt));  
  53.        bt.printInOrder();
  54.    }
  55.        
  56. }
  57.  
  58. You should build the binary tree in a static initializer block.
  59. Do not create a constructor.
  60. http://imgur.com/5NqP53S.png
  61.  
  62. Here's a sample JUnit assert:
  63.   assertEquals("LIONS TIGERS",MorseCodeTree.decode(".-.. .. --- -. ...  - .. --. . .-. ..."));
  64.  
  65. 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