// File: dice.jsl
// this represents a die
public class Dice
{
public Dice(int i)
{
numSides = i;
}
public int sides()
{
return numSides;
}
// number of sides on the die
private int numSides;
}
// File: app.jsl
public class App
{
public static int roll(Dice d)
{
java.util.Random r = new java.util.Random();
return (1 + r.nextInt(d.sides()));
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/