Question: Please help! I am to write a program to encode / decode messages from Morse code to standard letters and vice versa. Although digits and

Please help! I am to write a program to encode / decode messages from Morse code to standard letters and vice versa. Although digits and some punctuation marks exist in Morse code, we will only handle letters. The table showing Morse code is: A .- B -... C -.-. D -.. E . F ..-. G --. H .... I .. J .--- K -.- L .-.. M -- N -. O --- P .--. Q --.- R .-. S ... T - U ..- V ...- W .-- X -..- Y -.-- Z --.. Note that it is case insensitive (i.e. a and A are coded the same). Three spaces separate letters, and seven spaces separate words. So How are you is encoded as: .... --- .-- .- .-. . -.-- --- ..-

With this tree, to decode a Morse letter, start at the top of the tree, go through the code character by character, branching left for a dot and branching right for a dash. Once you have branched for each character in the code, you will be at the node storing the correct letter (e.g. trace --.- to see that you end up at the node with the letter Q). Design requirements 1. You have been provided with some starting code. Parts of the BTNode and BinaryTree class must be completed. See these files for more information. Do not modify the ArrayIterator. 2. Design your own classes (I currently have 5: two to encode/decode a letter. You must satisfy the following requirements: to decode Morse code messages: you must use the classes provided. You must implement the missing code. to build the tree, read the data from codes.txt. Note that each line contains a letter followed by a blank followed by the letters code. Note also that the data in the file is ordered by tree level initialize to anything it wont be used (although there is no order within a level). This means that as you build the tree, and want to add a new node for the letter just read, that you are guaranteed that the parent node already exists. You must use the file provided. provide a method called print which just uses the iterator provided with the Binary tree class to traverse the tree, printing out the nodes. This can be used to verify the tree is correct (before trying to use it to decode!). provide a method called decode which is passed the Morse code String for a letter, and returns the corresponding letter. the easiest way to decode an entire message is to store it in a String, and use the .split method with a parameter of a String of seven blanks. Since seven blanks separate words, this will return an array where each word is in an element of the array. You can use a similar technique (passing in a String of 3 blanks) to separate out the letters. You can assume that the message you are decoding will always be legal Morse code. both building the tree and decoding must be done with recursive methods. to encode messages into Morse code: use the same file (codes.txt) to read and store the required data (dont forget that you should always close a file when you have finished reading). set up a String array of length 26 to hold the codes for each letter. As code should go in position 0, B in 1 etc. provide a method called encode which is passed a letter and returns the corresponding Morse code String. it should be simple to encode an entire message once this array is set up dont forget to add 3 or 7 blanks as necessary. You can assume that the message you are encoding will always be legal i.e. it will contain only letters (upper or lower case) and blanks. the application to convert: ask the user if they want to encode / decode or quit, and keep looping until they quit. This should never bomb. If they choose to encode or decode, ask them to enter the message, then print out its translation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!