java die rolling code?

java die rolling code?
import java.util.Scanner;

public class Die
{
public Die(int s)
{
sides = s;
generator = new Random();
}
public int cast()
{
return 1+generator.nextInt(sides);
}
private Random generator;
private int sides;
}

class DieSimulator
{
public static void main(string[] args)
{
Die d=new Die(6);
final int TRIES = 10;
for (int i= 1; i<=TRIES; i++)
{
int n = d.cast();
System.out.print(n+" ");
}
System.out.println();
}
}
when i compile it cant find symbols our something
thank you for any help you can give me

Best answer:

public class Die
{
public Die(int s)
{
sides = s;
generator = new Random();
}
public int cast()
{
return 1+generator.nextInt(sides);
}
private Random generator;
private int sides;
THESE TWO LINES SHOW BE ON TOP

public class Die
{
private Random generator;
private int sides;
public Die(int s)
{
sides = s;
generator = new Random();
}
public int cast()
{
return 1+generator.nextInt(sides); is this correct??
}

Tags: , ,

Under Forum

1 Comment for java die rolling code?

  • 1. MyOhMyOhMy  |  January 30th, 2009 at 1:29 pm

    1. you have not imported java.util.Random
    2. The String in public static void main(string[] args) should have a Capital S
    3. Make those changes and the program should run. It gave me the following output (but then thats random)
    4 6 1 2 1 5 6 4 3 6

    Also, since you are not asking for user input you do not need to import the java.util.Scanner class

Leave a Comment for java die rolling code?

Required

Required, hidden

Trackback this post  |  Subscribe to the comments via RSS Feed


Forum