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 15 of 15

Thread: Creating a slang translator

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Creating a slang translator

    Hi,

    I recently had a friends son ( that is learning java on his own) ask me to create a simple sample urban slang translator, and since its been a few years since Ive messed around with java I am running into a problem. If my memory serves me correct I remember spending hours on a project only to realize all the problems I had were something silly. Anyhow, It seems I have gotten close except that my main problem is a big one, I cant seem to get the results returned. Since he only wants to screw around with turning an application into an app saving me some hours or days would be greatly appreciated. Im sure there is an easier way, but since I've came this far now I am the curious one. Here is where I'm at thus far.
    import java.util.Scanner;
    import java.awt.*;
    import java.util.*;
     
    public class Slang
    {
    public static void main(String[] args)
    {
    String[][] translateList = {{"a long time", "a minute"},
    {"opinion", "two cents" },
    {"dance", "two step"},
    {"attractive", "all that"},
    {"leave", "audi"},
    {"yes", "awe yeah"},
    {"no", "awe naw"},
    };
    Scanner scan = new Scanner(System.in);
    System.out.println ( "convert it to slang" );
    String sentence = scan.nextLine();
    String[] input = sentence.split("\\s");
     
    for (int x=0; x<input.length; x++)
    {
    for (int y = 0; y < translateList.length; y++)
    if (input[x].equalsIgnoreCase(translateList[y][0]))
    System.out.println("True");
    }
    }
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Creating a slang translator

    1. Java is an Object Oriented language. Use it's full potential.
    1a. Don't cram all your code into the main method.

    2. Your post is "Here's the code. It doesn't work. Fix it for me". That is not how it works. Ask a specific question, get a specific answer.

    3. Call me a skeptic but I have seen plenty of "This is not my homework" type of posts. It might fool some but those that it does you don't really want them doing your work for you.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Creating a slang translator

    LOL @homework.. its been over 20 years since ive done "homework".. You might want to check how to use quotes in English. Since no where in the post did I say "Here's the code. It doesn't work. Fix it for me" using quotes you are claiming that I did say that .. last but not least... I did state that i was having problems with returning the results.

    Heres a correct usage of quoting someone:
    "As time goes on we get closer to that American Dream of there being a pie cut up and shared. Usually greed and selfishness prevent that and there is always one bad apple in every barrel." -- Rick Danko

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Creating a slang translator

    No you didn't say it but it is implied. You post a backstory and some code but nowhere do you ask a question. So what are we supposed to do? The only thing that we can do is look at the code (possibly take a copy and compile it) then find and fix the problems. If that is not what you want then thanks for the story.
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Creating a slang translator

    Since the title of this forum is called "What is wrong with my code?" I figured it was obvious that someone who posts something would be asking for advice. By your response I guess it must obviously be titled wrong. If you don't want to help someone that posts here then maybe it should be called "The java programmers club only". god forbid that someone wants to play around with java as a hobby or just see if they can create something without having a formal education in that subject. I guess since your mood is grumpy a snarky remark should be expected.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Creating a slang translator

    To change back to the problem, what is your problem with the code you posted?
    If you have errors, please copy and paste the full text here.

  7. #7
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Creating a slang translator

    If you had read my entire post instead of having a hissy fit you would have noticed that it did include valuable advice.
    Quote Originally Posted by Junky View Post
    Ask a specific question, get a specific answer.
    Improving the world one idiot at a time!

  8. #8
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Creating a slang translator

    Thank you for the reply Norm. The program compiles fine no errors. I figure that I have forgotten something with returning the translated result using the string array ( as I believe its called). As of right now all its returning is "true" which I understand is because that's what I have in the quotes within my println. I have completed two working programs that work just fine one with a hashtable and another with the old If then statements, but curiosity has gotten the better of me when I attempted to try it this way. Just a point in the right direction would be greatly helpful thanks for your time.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Creating a slang translator

    right now all its returning is "true"
    By "returning" I guess you mean what the program is printing on the console screen.
    point in the right direction
    What do you want to be printed?

  10. #10
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Creating a slang translator

    yes that is correct.. I am looking for it to return the translated slang word. i.e. when they type in the word "opinion" I want "two cents" printed.
    I enjoy figuring these things out on my own but I am at a loss with this attempt.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Creating a slang translator

    All the Strings are in an array. Your code tests one part of the array at [0].
    You need to adjust the indexes into the array to get the other part at [1] that you want to print.

  12. The Following User Says Thank You to Norm For This Useful Post:

    TFG (July 27th, 2011)

  13. #12
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Creating a slang translator

    For starters it is not returning anything. Non-void methods return some value. All you are trying to do is display something but all that it does at the moment is print "TRUE". So you need to change that print statement to print the value you want instead, ie some String in the 2D translateList array.
    Improving the world one idiot at a time!

  14. #13
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Creating a slang translator

    Ok Thanks Norm.. I get the idea. As I said I did this already using a hashmap and with the if then statement now I am wondering in your professional opinion out of all these methods which would be considered the most efficient? It seems to me in my novice opinion using the hashmap "looked" the best.

    This is why I propagate corals on the professional level and dabble in programming as a hobby. Once again thanks.

  15. #14
    Junior Member
    Join Date
    Jun 2011
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: Creating a slang translator

    **EDIT. Oops didn't see the 2nd page. Here's my two cents anyway

    There's a few problems with your code, but if this is only a basic project, why not change:

    System.out.println("True");

    to:

    System.out.println(translateList[y][1]);

  16. #15
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Creating a slang translator

    @Diplo - I think the idea is that we help the OP find a solution himself, rather than spoon-feeding code.

Similar Threads

  1. PigLatin translator help
    By Rusak in forum What's Wrong With My Code?
    Replies: 10
    Last Post: April 6th, 2011, 07:53 AM
  2. having problems with my pig latin translator (the translating portion)
    By WontonSoup in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 12th, 2011, 06:45 PM
  3. Help with Pig Latin Translator...
    By jchan in forum AWT / Java Swing
    Replies: 3
    Last Post: September 28th, 2009, 02:54 PM
  4. creating a gui
    By rsala004 in forum AWT / Java Swing
    Replies: 2
    Last Post: July 21st, 2009, 02:17 AM
  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