public static int roll(Rollable d)
{
java.util.Random r = new java.util.Random();
return (1 + r.nextInt(d.sides()));
}
public static void main(String [] args)
{
// create a 6 sided die
Rollable d1 = new Dice(6);
for (int i = 0; i < 10; i++)
{
System.out.println(roll(d1));
}
// create an 8 sided die
Rollable d2 = new Dice(8);
for (int i = 0; i < 10; i++)
{
System.out.println(roll(d2));
}
}
}
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/