Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Random Insult Generator - Really Need Help

  1. May 27, 2008 #1
    I need to make this Random Insult Generator work... I mistakenly thought it had compiled correctly, but I guess something went wrong. I would really appreciate some help with this as soon as possible. Thanks (I apologize for the sloppy code, I just saw Java code for the first time a few weeks ago, so this is pretty alien to me):

     
  2. jcsd
  3. May 27, 2008 #2
    It would help to know what your error was :\

    I never used Java but if it's a syntax error you're getting:

    Random choice =new Random();

    Put a space between '=' and 'new'.
     
  4. May 28, 2008 #3

    Gokul43201

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Side note: 'goatstealing' is an adjective, not a verb.
     
  5. May 28, 2008 #4

    Defennder

    User Avatar
    Homework Helper

    I wonder what this program can possibly be used for...
     
  6. May 28, 2008 #5

    CRGreathouse

    User Avatar
    Science Advisor
    Homework Helper

    You would wonder that, you poxmarked, goatstealing blackguard!
     
  7. May 28, 2008 #6

    Dale

    Staff: Mentor

    I am not terribly familiar with Java, but it looks like you are using the length of adj verb and noun before they are defined.

    At the line
    int a = choice.nextInt(adj.length);
    the variable adj has not been defined so its length is also undefined (or at best 0)
     
  8. May 28, 2008 #7

    CRGreathouse

    User Avatar
    Science Advisor
    Homework Helper

    Yes, and the insult section doesn't need braces (though I don't think they hurt).
     
  9. May 28, 2008 #8
    :rofl: Those are some weak insults.
     
  10. May 28, 2008 #9
    Is this an attempt at an artificial Rodney Dangerfield ? That's not AI ...hehe it lacks the I part ..... j/k


    it's a good start at programming.
    Half is learning the silly syntax, half is learning what the routine is doing.
    I always found the first half harder.
     
  11. May 28, 2008 #10

    Dale

    Staff: Mentor

    Yeah, but in our over-sensitive politically-correct world a really good one would probably get you expelled :frown:
     
  12. May 28, 2008 #11
    Damn right!
     
  13. May 28, 2008 #12

    berkeman

    User Avatar

    Staff: Mentor

    It can be used for either, right? I was called a goatstealing fiend after I got caught goatstealing.
     
  14. May 31, 2008 #13
    Do testing :smile:
    Some suggestions:

    Code (Text):
    public static void main(String[] args)
    {//start main
    //variables
    String adj[] = { "poxmarked", "cantankerous", "bilestained", "scruffy looking"};
    String verb[] = {"goatstealing"};
    String noun[] = {"nerf herder", "blackguard"};

    Random choice =new Random();
    int a = choice.nextInt(adj.length);
    int b = choice.nextInt(verb.length);
    int c = choice.nextInt(noun.length);
    //Text
    System.out.println("You "+adj[a]+", "+verb[b]+" "+noun[n]+".");
    }
    Code (Text):
    public static void main(String[] args)
    {//start main
    //variables
    String adj[] = { "poxmarked", "cantankerous", "bilestained", "scruffy looking"};
    String verb[] = {"goatstealing"};
    String noun[] = {"nerf herder", "blackguard"};


    //Text
    System.out.println("You "+adj[0]+", "+verb[0]+" "+noun[0]+".");
    }
     
    Code (Text):
    public static void main(String[] args)
    {//start main
    //variables
    String adj[] = { "poxmarked", "cantankerous", "bilestained", "scruffy looking"};
    String verb[] = {"goatstealing"};
    String noun[] = {"nerf herder", "blackguard"};

    Random choice =new Random();
    int a = choice.nextInt(adj.length);
    int b = choice.nextInt(verb.length);
    int c = choice.nextInt(noun.length);
    System.out.println(" a = "+a+" b = "+b+" c = "+c);
    }
    If you don't find any problem, try compiling again or use different computer .. or restart ;)
     
  15. May 31, 2008 #14

    mathwonk

    User Avatar
    Science Advisor
    Homework Helper
    2015 Award

    your mother is so fat ........

    filling this in could substitute for a test grade in linear algebra perhaps.
     
  16. Jun 5, 2008 #15
    I did this once back in VB6 but I loaded up all my "literary devices" into text files then randomized results from those. It helps give you an easy way of managing your words.

    But yeah, it just looked like you tried using the objects before they were instantiated(created).
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Random Insult Generator - Really Need Help
  1. Random # Generator (Replies: 2)

Loading...