In this code I need to make the code handle characters in the message and not those in the input alphabet, without modifying the input alphabet to include the missing characters. I know I need to modify it so the jumble passes character in the message but not the input alphabet to the jumbledMessage, but I can't get it to work.Code:class TextJumble
{
public String jumble(String message, String input, String substitution)
{
int messageLength = message.length();
int inputLength = input.length();
String jumbledMessage = "";
String currentCharacter = "";
for (int i = 0; i < messageLength; i++)
{
currentCharacter = message.substring(i, i+1);
for (int j = 0; j < inputLength; j++)
{
if (currentCharacter.equals(input.substring(j, j+1)))
{
jumbledMessage += substitution.substring(j, j+1);
//What does this line do? How does it affect the inner for loop?
//This line
j = inputLength;
}
}
}
return jumbledMessage;
}
public static void main(String[] args)
{
TextJumble obj = new TextJumble();
String originalString = "This is the original message! It contains charaters that are not in the ";
originalString += "the input alphabet. Test sysmbols: !@#$%^&*(){}";
String inputAlphabet = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
String substitutionAlphabet = "ghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdef";
String jumbledString = obj.jumble(originalString,
inputAlphabet,
substitutionAlphabet);
System.out.println("jumbledString: " + jumbledString);
String unjumbledString = obj.jumble(jumbledString,
substitutionAlphabet,
inputAlphabet);
System.out.println("unjumbledString: " + unjumbledString);
System.out.print("The test to jumble and unjumble the original string ");
if (unjumbledString.equals(originalString))
{
System.out.println("passed.");
} else {
System.out.println("failed.");
}
}
}
Once the method has been modified correctly the expression for the if statement on line 53 will evaluate to true, but I can't get this.
My output keeps being:
Quote:
> run TextJumble
jumbledString: ZnoyFoyFznkFuxomotgrFskyygmkFFOzFiutzgotyFingxgzkx yFzngzFgxkFtuzFotFznkFznkFotv zFgrvnghkzFFZkyzFyDyshuryF
unjumbledString: This is the original message It contains charaters that are not in the the input alphabet Test sysmbols
The test to jumble and unjumble the original string failed.
>
