Need help

This is my main class, which creates an object of type random and sends it to another class. Why can't I then get a random number to generate in the second class?

import java.util.Random;

public class SchoolYear

{

public static void main(String[] args)

{

Random rand = new Random();

ArithmeticQuestion arithmetic = new ArithmeticQuestion(rand);

int ans1 = arithmetic.ask();

}

}

import java.util.Random;

import java.util.Scanner;

public class ArithmeticQuestion

{

Random rand;

public ArithmeticQuestion(Random rand)

{

rand = this.rand;

}

public int ask()

{

int num1 = (int)Math.ceil(20*rand.nextDouble());

int num2 = (int)Math.ceil(20*rand.nextDouble());

Scanner scan = new Scanner(System.in);

System.out.println("What is " + num1 + " + " + num2);

int answer = scan.nextInt();

return 0;

}

}

[981 byte] By [Rhett777a] at [2007-10-2 1:58:08]
# 1
> rand = this.rand;Try:this.rand = rand;
warnerjaa at 2007-7-15 19:39:22 > top of Java-index,Java Essentials,Java Programming...
# 2
.....thank you, it's been a while since I've used java
Rhett777a at 2007-7-15 19:39:22 > top of Java-index,Java Essentials,Java Programming...
# 3
I think that the probelm is in the constructor.changerand = this.randto this.rand = randyou were setting the main rand to null.
kris.richardsa at 2007-7-15 19:39:22 > top of Java-index,Java Essentials,Java Programming...