Morse Code Converter

CPE 103 Programming Project

Goal

The goal of this project is to write a Java program to convert Morse Code to English and vice versa.

Overview

The binary tree below can be used to decode Morse code.  Each left child represents a "dot" in the code, and each right child represents a "dash."  Thus the sequence "..-" (dot dot dash) decodes to the letter U.  


                                   (root)               
                                     |                   
                         -------------------------       
                       /                            \       
                     /                                \    
                   /                                    \    
                 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


English text can be translated to Morse Code using a simple table lookup.

You are to write a Java class that encapsulates the tree structure above and provides operations for converting to and from Morse Code.

Decoding

    The morse code text is sequences of dots (periods), and dashes, separated by blank spaces.  A single blank character must separate each "letter" (1 to 4 symbols).  Extraneous blanks between "words", at the beginning or at the end, are echoed to the output. Any other characters are ignored.  The string does not need to end with a blank.
    English text is output in upper case. 

Encoding
    Any string may be entered, but only letters A-Z (lower or upper case) will be encoded. Blanks are allowed and are simply echoed to the output without encoding.
    Morse code is output with dots and dashes.  A blank follows each "letter" (1 to 4 symbols).

Software Design

Click on a class in the diagram to view the javadocs.

class diagram

You are to implement two classes in the above design. Your public interface must match the class specifications exactly.

BinaryTree, which implements the I_BinaryTree Interface.   You must use a linked implementation.  Your implementations must match the javadoc class specifications exactly. (If you say "implements I_BinaryTree", then the compiler will ensure that your specification matches.)

CodeTree, the morse code converter client application.  It provides static methods for decoding and encoding morse code.

Here are the .class files for the instructor components, in a JAR formatted file:   MorseComponents.jar

Sample Test

  assertEquals("LIONS TIGERS",CodeTree.decode(".-.. .. --- -. ...  - .. --. . .-. ..."));
  assertEquals(".-. .- - ",CodeTree.encode("RAT"));

Implementation Constraints

Your solution for decoding morse code must be implemented using a tree structure as shown above.  That is, each morse code "letter" must be decoded by looking up its english equivalent in a binary tree like the one shown. You may build the binary tree in a constructor method if you wish, or define it statically. For encoding morse code you must not use a big switch statement.  You may use a lookup table (an array of strings).  

Testing

Your components will be tested with instructor reference tests.  The reference tests are JUnit tests of your classes. 

On this project your solution must conform to the class coding standard. Your unit tests must demonstrate "statement" coverage (they cause every statement in your program to be executed.)

Handing in Your Source Electronically


Tip
Since the only methods in the CodeTree class are static methods,
don't expect that someone using your class will invoke the constructor.

For example, when you use Math.Random(), you don't create a new Math()
beforehand.  

So when someone uses CodeTree.encode(), they won't create a new CodeTree()
beforehand.

To be safe, don't even write a constructor.

Q: OK, you may ask, then how do I initialize the binary tree?
A: Probably the best way is with a static initializer block.

If you haven't done this before, you can look it up in your Java
reference.  Or a quick web search turned up this reference
which I haven't read, but might help:

Static Initializer Blocks