Why Does My Java Random Insult Generator Not Compile?

In summary, the conversation revolved around a program for generating insults and the need for help with its functionality. The code for the program was provided, along with suggestions for improvements and clarifications on syntax errors. The conversation also touched on the potential uses for the program and tips for managing the words used in the insult generation.
  • #1
GobiasMoleman
1
0
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):

//InsultGenerator
//A program to generate insults.

import java.text.*;
import java.util.*;
import java.util.Random;

public class InsultGenerator
{//start
public static void main(String[] args)
{//start main
//variables
Random choice =new Random();
int a = choice.nextInt(adj.length);
int b = choice.nextInt(verb.length);
int c = choice.nextInt(noun.length);
//insult
{//start insult
String adj[] = { "poxmarked", "cantankerous", "bilestained", "scruffy looking"};
String verb[] = {"goatstealing"};
String noun[] = {"nerf herder", "blackguard"};
}//end insult
//Text
System.out.println("You "+adj[a]+", "+verb+" "+noun[n]+".");}
}//end main
 
Technology news on Phys.org
  • #2
GobiasMoleman said:
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):

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'.
 
  • #3
Side note: 'goatstealing' is an adjective, not a verb.
 
  • #4
I wonder what this program can possibly be used for...
 
  • #5
Defennder said:
I wonder what this program can possibly be used for...

You would wonder that, you poxmarked, goatstealing blackguard!
 
  • #6
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)
 
  • #7
DaleSpam said:
it looks like you are using the length of adj verb and noun before they are defined.

Yes, and the insult section doesn't need braces (though I don't think they hurt).
 
  • #8
:smile: Those are some weak insults.
 
  • #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.
 
  • #10
_Mayday_ said:
:smile: Those are some weak insults.
Yeah, but in our over-sensitive politically-correct world a really good one would probably get you expelled :frown:
 
  • #11
Damn right!
 
  • #12
Gokul43201 said:
Side note: 'goatstealing' is an adjective, not a verb.

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

Code:
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:
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:
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 ;)
 
  • #14
your mother is so fat ...

filling this in could substitute for a test grade in linear algebra perhaps.
 
  • #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).
 

Related to Why Does My Java Random Insult Generator Not Compile?

1. How does the Random Insult Generator work?

The Random Insult Generator uses an algorithm to randomly select words and phrases from a database of insults and combine them to create unique insults. The algorithm takes into account parts of speech and sentence structure to create insults that make grammatical sense.

2. Can I customize the insults generated?

Yes, the Random Insult Generator allows for customization of the insult database. Users can add their own insults or remove existing ones to make the generator more personalized.

3. Is the Random Insult Generator appropriate for all ages?

No, the Random Insult Generator may generate insults that contain vulgar language or inappropriate content. It is recommended for mature audiences only.

4. How accurate are the insults generated by the Random Insult Generator?

The accuracy of the insults depends on the size and quality of the insult database. With a large and diverse database, the insults generated can be quite accurate and creative.

5. Can the Random Insult Generator be used for any purpose?

The Random Insult Generator is intended for entertainment purposes only and should not be used to bully or harass others. It is the user's responsibility to use the generator responsibly and ethically.

Similar threads

  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
2
Views
6K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
9
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
2
Replies
37
Views
4K
  • Programming and Computer Science
Replies
3
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
Back
Top