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.
Updated 10/25:
The morse code text is sequences of dots (periods),
and dashes, separated by blank spaces. At least one blank character
must separate each "letter" (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.
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.

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 should build the binary tree in a static initializer block.
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
- Make sure the @author tag is correct in every source file you submit.
If you worked in a pair, include both student's names.
- Submit a zip file containing your source code and unit tests to
Web-CAT. You do not need to submit MorseComponents.jar.
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, 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 read about it
here.
FAQ
Q: When I run my program I'm getting an error "Illegal Access Exception". It
compiles fine.
A: I've investigated this and can't determine why it's happening for some
students. At the moment, the workaround I can suggest is to use the CSL
workstations. Alternatively, you can work on the CSL servers via ssh,
and from the command line you can compile and run your tests like this:
javac -cp MorseComponents.jar BinaryTree.java
javac -cp MorseComponents.jar CodeTree.java
javac -cp MorseComponents.jar:/home/graderjd/bin/junit-3.8.1.jar:. BinaryTreeTest.java
java -cp MorseComponents.jar:/home/graderjd/bin/junit-3.8.1.jar:. junit.textui.TestRunner BinaryTreeTest
Update! I've discovered that this problem occurs only using BlueJ
Version 3.
The very first lab we did in the course recommends version 2.5.3.
If you install the recommended version the "Illegal Access Exception" will
go away.
Q: Shouldn't Element extend Comparable?
A: No, because this isn't a binary SEARCH tree, it's just a Binary Tree,
so insert doesn't look at the node contents, it inserts items based on
the Relative position.
Q: I was writing my traverse() and am confused about
the returning a String part. The javadocs specify that each
nodeData is added to a string, but the BinaryNode's are (quite
obviously) generic. I am wondering how to circumvent this, as I can't add
the nodeData of type Element to a String.
A: Just call toString() on the nodeData.
It's the responsibility of the client to make sure that whatever
they pass you for Element has a toString() method.