Results 1 to 2 of 2
  1. #1
    switun22 is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Default Help with TextJumble

    Java 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.");
            }
        }
    }
    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.

    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:
    > 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.
    >
    Last edited by Norm; 09-15-2011 at 03:04 PM. Reason: changed quote to code tags

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Help with TextJumble

    My output keeps being:
    What should the output be?
    Can you explain what the code in the jumble method is doing and what it is supposed to do?
    It appears to concatenate some substrings. What determines what the substrings should be?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •