Java Pig Latin Code

Discussion in 'OT Technology' started by Yoshiemaster, Sep 21, 2005.

  1. Yoshiemaster

    Yoshiemaster New Member

    Joined:
    Sep 17, 2005
    Messages:
    1,972
    Likes Received:
    0
    Location:
    Raleigh, NC
    can anyone help me out with this? i want to translate "mary had a little lamb", but i don't want to use the scanner class.
     
  2. Bruticus

    Bruticus half dead OT Supporter

    Joined:
    Apr 10, 2004
    Messages:
    4,608
    Likes Received:
    0
    Location:
    Melbourne
    As in you want to switch the letters around to pig latin format? ie mary = yarm ?
     
  3. Yoshiemaster

    Yoshiemaster New Member

    Joined:
    Sep 17, 2005
    Messages:
    1,972
    Likes Received:
    0
    Location:
    Raleigh, NC
    no, mary= arymay

    first letter gets copy pasted to the end of the word. add ay.
     
  4. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    You probably want to start by tokenizing the string (dividing it up into words). Then, process each word.
     
  5. Bruticus

    Bruticus half dead OT Supporter

    Joined:
    Apr 10, 2004
    Messages:
    4,608
    Likes Received:
    0
    Location:
    Melbourne
    Yeh thats what I'd do, break it up in bits, then just create the new word. Add into one big string at the end if that's what you need.
     
  6. Yoshiemaster

    Yoshiemaster New Member

    Joined:
    Sep 17, 2005
    Messages:
    1,972
    Likes Received:
    0
    Location:
    Raleigh, NC
    i got it.

     
  7. MovieMan84

    MovieMan84 Here we go

    Joined:
    Sep 10, 2002
    Messages:
    4,374
    Likes Received:
    0
    Location:
    Redmond
    That works, but that's a rather ghetto solution. Ideally you'd just have one output word. Tokenize the string to get each input word in an array (or some other collection...linked list would be swell). Iterate over your collection and one at a time and use the string.length property (i think this is correct in java...) to figure out where the beginning, end, and first character of it are. What you did technically does work but it shows very little programming skill (unless this is how you're supposed to do it, then I suppose it's fine.)
     
  8. Yoshiemaster

    Yoshiemaster New Member

    Joined:
    Sep 17, 2005
    Messages:
    1,972
    Likes Received:
    0
    Location:
    Raleigh, NC
    eh, it's my 5th week of java. i'm taking AP Computer Science A
     
  9. MovieMan84

    MovieMan84 Here we go

    Joined:
    Sep 10, 2002
    Messages:
    4,374
    Likes Received:
    0
    Location:
    Redmond
    Oh my bad...I didn't realize this was a HS course. We had to do a similar problem in CS1 at my university only with the length property and an unknown number of words being changed, so that's why I made the comment.

    If your assignment is to hard-code it for exactly 5 input words then it looks like you're good to go.
     
  10. Corp

    Corp OT Supporter

    Joined:
    Sep 11, 2003
    Messages:
    28,201
    Likes Received:
    0
    Location:
    Providence, RI
    if it's an ap class, shouldnt you already know enough to do it the right way? we did this program with the user inputting whatever they wanted when i was just in regular programming class.
     
  11. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,924
    Likes Received:
    11
    Location:
    Los Angeles
    Not all programming classes or schools teach the same method or apply the same methods that yours did.
     
  12. Yoshiemaster

    Yoshiemaster New Member

    Joined:
    Sep 17, 2005
    Messages:
    1,972
    Likes Received:
    0
    Location:
    Raleigh, NC
    you mean using the scanner class. we can't. some fag tech guy who works at my school was supposed to re-image the computers. some file was corrupt and now the computers in our lab won't work. so we were told to write the code w/o the scanner class.
     
  13. Yoshiemaster

    Yoshiemaster New Member

    Joined:
    Sep 17, 2005
    Messages:
    1,972
    Likes Received:
    0
    Location:
    Raleigh, NC
    we're pretty much neck and neck with North Carolina State University's Computer Science A course. you know how i know? my APCS teacher teaches us in the morning, and then goes to NCSU in the afternoon. with a 96 in that class, and a recommendation from my teacher. i'm pretty much in NCSU.
     
  14. Corp

    Corp OT Supporter

    Joined:
    Sep 11, 2003
    Messages:
    28,201
    Likes Received:
    0
    Location:
    Providence, RI
    true.

    thats pretty :cool:
     
  15. Yoshiemaster

    Yoshiemaster New Member

    Joined:
    Sep 17, 2005
    Messages:
    1,972
    Likes Received:
    0
    Location:
    Raleigh, NC
    ahah i thought u were making fun of me, then i scrolled over the smilie and i put 2 and 2 together....
     
  16. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    javadoc: string, stringbuffer, and associated functions. Get yourself a little reference book that has things like the string functions in them, and use it. Or look them up on the web. Try to LEARN something: Make a class with a function that takes a string as input, breaks the words into individual strings, puts the first letter at the end, and adds ay.

    Not hard. What you did... it didn't teach you anything. Try not to sabotage your education... :(
     
  17. Yoshiemaster

    Yoshiemaster New Member

    Joined:
    Sep 17, 2005
    Messages:
    1,972
    Likes Received:
    0
    Location:
    Raleigh, NC
    yea..
     
  18. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    You're ahead of the first comp sci class at my university. They're still learning to draw houses in Java applets. Stupidest idea for a lab ever, the course needs to be re-thought in a serious way.

    As for the actual problem, Java has a tokenizer class that you may or may not be allowed to use. If can use it, it'll do much of the work for you.
     
  19. Corp

    Corp OT Supporter

    Joined:
    Sep 11, 2003
    Messages:
    28,201
    Likes Received:
    0
    Location:
    Providence, RI
    i'm a first year comp sci major, and right now we're doing c++. all we've done so far is cin and cout really. luckily i tested out of the really basic class, otherwise i think i'd shoot myself.
     
  20. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    Here is an optimized version of your code! Check it out!

    Code:
    public class PLTranslator {
    public static void main(String[] args) {
    
    String string1 = "Mary Had A Little Lamb";
    String string2 = "Arymay adhay ittlelay amblay";
    System.out.println("What you entered: "+string1+"\nWhat you entered in pig latin: "+string2+".\nI Need to learn how to code.");
    }
    }
    
    OR

    Code:
    public class PLTranslator {
    public static void main(String[] args) {
    
    System.out.println("What you entered: Mary Had A Little Lamb.\nWhat you entered in pig latin: Arymay adhay ittlelay amblay.\nI Need to learn how to code.");
    }
    }
    
    Cause if you are going to hard code it like that, if I was the prof, i'd ask you to widthdraw and find a new profession.

    Yes I'm being harsh, but its the truth.
     
  21. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    They use Java for the first-year courses here. Not a bad idea, IMO, but they shouldn't be drawing houses in applets as their first lab, it's just stupid.

    I could have bypassed my first two courses (since I had a 5 on my AP Comp Sci AB), but I figured they would be two easy 4.0's in a first year that had to include some arts and "real" science courses that I'm not so good at, so I took them anyway.
     
  22. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Some nerds are such assholes.
     
  23. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    Your pig-latin converter is not completely correct. It works for the simple string you provided but more complex words will end up incorrect. In pig-latin, you take the leading consonants off and put them at the end so the new word starts with a vowel. In your program, you just take off the beginning letter and put it at the end. So, if someone inputs the word "show" your program will output "howsay" but the proper word would be "ow-shay." That brings up another point, all the pig-latin I have seen uses a dash to seperate the parts of the word.
     
  24. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    :wiggle: :mamoru:
     
  25. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    :rofl:

    It's true though. As a group, nerds and geeks are such "elitists"[font=&quot][/font]. Not referring to anyone specifically. :mamoru:
     

Share This Page