This assignment will give you practice with trees. You are to write a class MorseCoder that allows you to encode and decode Morse code.
The Morse code (see Table 6.10) is a common code that is used to encode messages consisting of letters and digits. Each letter consists of a series of dots and dashes; for example, the code for the letter a is •– and the code for the letter b is –•••. Store each letter of the alphabet in a node of a binary tree of level 5. The root node is at level 1 and stores no letter. The left node at level 2 stores the letter e (code is •), and the right node stores the letter t (code is –). The 4 nodes at level 3 store the letters with codes (••, •–, –•, ––). To build the tree (see Figure below), read a file in which each line consists of a letter followed by its code. The letters should be ordered by tree level. To find the position for a letter in the tree, scan the code and branch left for a dot and branch right for a dash. Encode a message by replacing each letter by its code symbol. Then decode the message using the Morse code tree.
Your class must implement the MorseCodeInterface provided and must contain the methods specified. You may need to provide a constructor to build the tree from the input file, encodings.txt. You may create private methods to implement the recursion for the different methods.
You are allowed to declare whatever data fields you want for your class, but you should try to keep these to a minimum. You can get by with just one data field (possibly root) and you shouldn’t need much more. If you have unnecessary data fields (data fields that could be turned into local variables), you will lose style points.
In terms of correctness, your class must provide all of the functionality described above. In terms of style, we will be grading on your use of comments, good variable names, consistent indentation and good coding style to implement these operations.
You should name your file MorseCoder.java and you should turn it in electronically from the “assignments” link on the class web page. You will need to have MorseCodeInterface.java, MorseNode.java, MorseMain.java and encodings.txt (In the same level as src) all in the same directory as your MorseCoder.java in order to run MorseMain. A sample output file, output.txt file is also attached.
You may work on this assignment in pairs.
Laura Peterson wrote:Any help and advice as far as fixing those bugs for the correct output would be welcomed.
Laura Peterson wrote:Thanks for the new thought process. I think I'm understanding a little better now. Thank you!
Laura Peterson wrote:Any help and advice ... would be welcomed.
Campbell Ritchie wrote:Where does that code come from? Why does it look so similar to Laura Peterson's, even with the same mistakes repeated? Are you on the same course as her?
I would probably not now design the node like that; I would make the letter final and I would give it a morseCode field. Once you add that field it becomes very easy to print S ... because the Node or some MorseCode object will encapsulate both data.
I would probably also make MorseCode implement Comparable<MorseCode>, or write a Comparator. You should be able to make those consistent with equals(), and you can create a tree around that.
I don't think you need worry about that after six years.
Peter Ream wrote:I Know this is an old thread . . . neither of the posters provided a working method. . . . .
I shall have to study your code before I understand that bit, but I haven't got the time to do it now.
What I tagged as "// Recursive return" were returns not actually returning a result, but justing going deeper into the tree.
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDFhtttp://www.e-iceblue.com/free-apis.html