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;
}
}

