Question: JAVA PLEASE 1 . Store each letter of the alphabet in a binary tree. The root node stores no letter. 2 . Travel to the

JAVA PLEASE
1. Store each letter of the alphabet in a binary tree. The root node stores no letter.
2. Travel to the left represents a dot and travel to the right represents a dash. Build the tree using the
Morse code to travel left or right and then insert the letter.
a.Initially the tree has a root node with no data.
b.Read the first line of the text file: e o Letter e is represented by a single dot. Travel begins from the
root. Dot means travel left. There is no left child encountered so make a node and insert letter
c.Read the next line of the text file: t
-Letter t is represented by a single dash. Travel begins from the
root. Dash means travel right. There is no right child so make a node and insert letter t
d.Read the next line of the text file: i oo Letter i is represented by a two dots. Dot means travel left. The
first left goes to node e.There is no left child of e so make a node and insert letter i
e.Repeat this process until all letters have been processed from the file and inserted into the tree.
The program will also use an array to store the code for each letter. Store the code for the letter at the
index using its ASCII code to determine position. The ASCII sequence for 'a'...'z' begins at code 97. Morse code for 'a' is stored in index 0,Morse code for 'b'is stored in index 1,etc. You can compute thearray index (ex.0)from the letter (ex.'a')by subtracting 97from the letter.
char letter ='a';
int index =(int)letter 97; //(int)'a'returns 97and subtract 97returns 0
//code for letter a (o-)is stored at index 0
letter ='b';
index =(int)letter 97; //(int)'b'returns 98and subtract 97returns 1
//code for letter b (-ooo)is stored at index 3. Report the preorder traversal of the tree. If your answer does not match the output shown, your tree is not built correctly so do not continue until this part is done. This code should write the recursive method shown.
//display a preorder traversal of the tree
public static void preOrderDisplay (TreeNode node)
4.After the two data structures are filled, run an interactive program where the user enters an English
word in lower case. Report the Morse code equivalent using the array with character /to separate codes, and then decode the Morse code string back to English using the tree.
Use this code: // TreeNode models a node for a binary tree
package binarytree;
public class TreeNode {
private T element; // data field
private TreeNode left; // reference to left
child node
private TreeNode right; // reference to right
child node
public TreeNode()// POST: empty
tree node
{ element = null;
left = right = null; }
public TreeNode (T elem)// POST: tree node with
element set
{ element = elem;
left = right = null; }
public TreeNode (T elem, TreeNode left, TreeNode right)
{ element = elem; // POST: tree node
with all fields set
this.left = left;
this.right = right; }
// accessors and modifiers
public T getElement(){ return element; }
public void setElement(T element){ this.element = element; }
public TreeNode getLeft(){ return left; }
public void setLeft(TreeNode left){ this.left = left; }
public TreeNode getRight(){ return right; }
public void setRight(TreeNode right){ this.right = right; }
public boolean isLeaf ()// POST: return true if node is a leaf node
{ return (left == null && right == null); }
}
JAVA PLEASE 1 . Store each letter of the alphabet

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 Accounting Questions!