i have an assignment. i have done all the parts of the assignment. but i am strucked in below part of my assignment. can you help me
Assignment guidelines
III.Write one constructor method for the EncryptedNode class. This constructor should take a String as an argument. Unlike other constructors you have written, this constructor should function conditionally. If the message is one character long, simply assign that character to the letter instance variable. If the message is two characters long, assign the first character to the letter, and the other character as a string to the right EncryptedNode. In any other case, find the middle value of the input String, assign the character at the first index to letter, characters
from 1 up to the middle character should go to the right EncryptedNode, and the remaining unclaimed
characters should go the left EncryptedNode. Note: you will be instantiating new EncryptedNode objects from this constructor, thus creating a recursive construction.
IV. Write the following methods:
a. The decrypt method takes no arguments and returns a String. This method should re-build the original unencrypted String by adding the letter, left and right elements of each EncryptedNode recursively. This process will be left to you to solve.
my sample code is
class EncryptedNode {
public EncryptedNode left, right ;
public char letter ;
// EncryptedNode Class constructor method.
public EncryptedNode (String message) {
// get String length
int message_length = message.length() ;
if (message_length == 1) {
this.letter = message.charAt(0) ;
}else if (message_length == 2) {
this.letter = message.charAt(0) ;
this.right = new EncryptedNode (message.substring(1));
} else {
this.letter = message.charAt(0) ;
// get the middle index of the message string.
int middle_index = message.substring(1).length() /2 ;
// get left and right strings
String rightStr = message.substring(1,middle_index+1);
String leftStr = message.substring(middle_index+1);
this.left = new EncryptedNode (leftStr);
this.right = new EncryptedNode (rightStr);
}
System.out.println (this.letter);
// System.out.println (this.right);
}
public static void main (String [] args) {
EncryptedNode en = new EncryptedNode("ABCDEF") ;
en.decrypt();
}
public String decrypt () {
if (this.left == null && this.right==null) {
return this.letter;
}else if (this.left == null && this.right != null) {
return this.letter + this.right;
}else if (this.left !=null && this.right != null) {
return this.left + this.letter + this.right;
}
}
}