Provide yourself an example (not one from your instructor) of how you use a particular command that will help jog your memory in the future when you need that command again. You must provide a little code as well as a written explanation with this one.
A class called Random Generator helps programmers use random numbers and simulations in their programs. If you wanted to make a die that makes any number between 1 to 6 randomly, this class would be of great help. Look at the following example:
import java.util.Random;
public class Dies { public Dies (int s)
{
sides = s; generator = new Random();
}
public int cast()
{
return 1 + generator.nextInt(sides);
}
private Random generator;
private int sides; //private int sides2;
}
It a testing class was made, it would provide any random number between 1 and 6 just like a die would. Thus, the Random class is very important. (I am going to use it in the GameLand project.)
Wednesday, November 14, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment