Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: English to L33T Translator

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default English to L33T Translator

    Hi all,

    Working on a simple english to L33T Translator (using the java.lang.String ), below is my code:

    Basically what I'm trying to do is get an input sentence from a user, isolate that sentence character by character (with each character getting passed to the translate method), and making the swap by mapping equivalents from english to l33t data structures (currently not working as desired)

    public static void main(String[] args) {
     
    		Scanner scan = new Scanner(System.in);
    		System.out.println("Please enter a sentence to translate to L33T: ");
    		String sentence = scan.nextLine();
    		String result = ""; 
     
    		for (int i = 0; i < sentence.length(); i++) {
     
    			result += translate(sentence.substring(i,i+1));
     
    		}
     
    		 System.out.println(result);
    	}
     
     
     
     
     
    	public static String translate (String str) { 
     
    		String result = ""; 
    		String[] english = {"A", "a", "B", "C", "E", "G", "g", "H", "I", "i", "L", "O", "R", "S", "T", "X", "Z"};
    		String[] leet = {"4" , "@", "8" , "(" , "|)", "3", "6", "9", "#" , "1", "!", "1", "0", "12" , "5", "7", "†", "x", "2"}; 
     
    		for (int i = 0; i < english.length; i++) {
     
    			if (str.equalsIgnoreCase(english[i])){
     
    				result += leet[i];
     
    			}
     
    		}
     
    		return result;
    		}


    if a character (including other letters or numbers, space, etc.) does not have an alternative in the table, leave it as is


    Where am I going wrong?

    Appreciate the help

    Thanks !


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: English to L33T Translator

    Is this the same problem as this:
    http://www.javaprogrammingforums.com...ranslator.html

    Why not continue on the first thread?

    Where am I going wrong?
    Please show what the program is currently doing and explain what is wrong with it and show what it should do.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: English to L33T Translator

    You told me to post a new thread, so I did.

    As I said, the goal is to successfully translate a sentence (which will be taken as input from the user) from English to L33T based on the arrays provided. Currently, that translation is not working - I am getting the wrong output characters.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: English to L33T Translator

    I am getting the wrong output characters.
    Please show what the program is currently doing and explain what is wrong with it and show what it should do.

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: English to L33T Translator

    Here is a screenshot of the output:

    Image - TinyPic - Free Image Hosting, Photo Sharing & Video Hosting

    I should be getting "#3110" for the output (the LEET translation for Enlgish)

    Why is this happening and how do I fix it.

    Remember that if there is no translation in the key, we leave the letter as is

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: English to L33T Translator

    Try debugging the code by adding printlns that show what is happening.
    For simplicity, give the program one or two letters as input. Print out everything that happens in the translation to see where the code is going wrong.
    For example if you give it "H" you should get out a "#"?
    "HE" should give "#3"

  7. #7
    Junior Member
    Join Date
    Sep 2011
    Posts
    24
    My Mood
    Mellow
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: English to L33T Translator

    I don't know if this crosses the line in to spoon feeding, but it looks like he just forgot to put "D" in to his english array. He has the whole idea right, he just made a typo.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: English to L33T Translator

    @DougFane Do you know the definition of the L33T language? What letters are translated and what letters stay the same.
    The OP should certainly line up the two arrays and see if the corresponding letters match as expected.
    Last edited by Norm; January 29th, 2012 at 09:59 PM.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: English to L33T Translator

    Where are you? After PMing me 3 times to give you help, you seem to have lost interest in working on a solution.

  10. #10
    Junior Member
    Join Date
    Sep 2011
    Posts
    24
    My Mood
    Mellow
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: English to L33T Translator

    No I just saw that there was a l33t string of "|)" that did not make sense for any english string but "D" and all of his outputs were off by one, which could indicate that there is an element missing from the array.

Similar Threads

  1. English to L33T Translator
    By eeengenious in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 28th, 2012, 07:19 AM
  2. need details on Implementing Dictionary Filters for English words
    By madcrazyboys in forum Java Theory & Questions
    Replies: 2
    Last Post: May 6th, 2011, 12:53 PM
  3. Translate Java Code Into English
    By drkossa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2009, 02:52 PM
  4. Help with Pig Latin Translator...
    By jchan in forum AWT / Java Swing
    Replies: 3
    Last Post: September 28th, 2009, 02:54 PM
  5. Pig Latin Translator
    By BMN901 in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: June 17th, 2009, 03:31 AM