/** A TrickDice has one weightedSide such that the * weightedSide appears weight times as often as other sides */ class TrickDice extends Dice { private int weightedSide; //weighted side appears more often private int weight; //weighted side appears weigth //times as often as other sides /** TrickDice has side s appearing with weight w */ public TrickDice(int numFaces, int s, int w) { super(numFaces); weightedSide= s; weight= w; roll(); } /** Bogus method to test access to some components */ public void foo() { System.out.println(weight); //valid? //System.out.println(sides); //invalid. System.out.println(getSides()); //valid? roll(); //which version of roll() will be executed? } /** top gets random value in 1..sides given trick property */ public void roll() { //int r= (int) (Math.random()*(getSides()+weight-1))+1; int r= randInt(1,(getSides()+weight-1)); if (r<=getSides()) setTop(r); else setTop(weightedSide); } /** = Get weighted side */ public int getWSide() { return weightedSide; } /** = Get weight of weighted side */ public int getWeight() { return weight; } }