Rollable d = new Dice(i);
return d;
}
}
// File: app.jsl
public class App
{
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)
{
// creation of dice is done through the factory
// create a 6 sided die
Rollable d1 = DiceFactory.create(6);
for (int i = 0; i < 10; i++)
{
System.out.println(roll(d1));
}
文章来源于领测软件测试网 https://www.ltesting.net/