Write a class that uses a binary tree (as shown below) to decode a string representing Morse code. This string will use “-“ to represent Dash and “.” To represent Dot. See image.
The Morse code string is kept in a file. MorseTester.java reads this text and sends it to MorseCodec.java which scans the text and sends it, one word at a time to your class, MorseDecoderTree.java. Your code will use MorseDecoderNodes to build a tree as shown above. You will write a method called convert to decode a string.
The class named MorseDecoderTree builds a binary tree of nodes
Add bodies to the constructor MorseDecoderTree and the method convert . The constructor should build the Morse code tree by creating an overall node and a node for each symbol A-Z and 1-0, making links between the nodes as shown in the diagram above. The convert method takes a String as input and returns the plain text that corresponds to the given Morse code.
The provided file, AlphabetInMorse.txt, contains the letters A through Z and the digits 1 through 0. The test driver, MorseTester, produces this output
Before conversion: ->.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. .---- ..--- ...-- ....- ..... -.... --... ---.. ----. ----- <-
After conversion: ->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 1 2 3 4 5 6 7 8 9 0 <-
Write a class, MorseEncoderMap.java, that uses a Map
The text string is kept in a file. MorseTester.java reads this text and sends it to MorseCodec.java which scans the text and sends it, one word at a time to your class, MorseEncoderMap.java. Your code will use a Map Character, String to build a lookup table as shown below. You will write a method called convert to decode a string. See image.
Add bodies to the constructor MorseEncoderMap and the method convert . The constructor should build the Map as shown in the diagram above. The convert method takes a String as input and returns the Morse code that corresponds to the given plain text.
The provided file, AlphabetInMorse.txt, contains the letters A through Z and the digits 1 through 0. The test driver, MorseTester, produces this output
Before conversion: ->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 1 2 3 4 5 6 7 8 9 0 <-
After conversion: ->.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ..--- ...-- ....- ..... -.... --... ---.. ----. ----- .--- <-