/** ** AnySidedDie is a class each instance of which models an n-sided ** (and possibly unfair) die, such as is used in games of chance and ** board games. ** ** @author Bob McCloskey ** @author < your name > ** */ public class AnySidedDie { /* c o n s t r u c t o r s */ /** ** Class constructor that produces an n-sided die, where n is the ** length of the array argument. Each side's probability of being ** the result of a toss is given by the ratio of its corresponding ** element in the array to the sum of the array elements. For example, ** suppose that freq[1] = 3 and that the sum of the elemements in ** freq[] is 10. Then the probability of tossing a 2 is 3/10 (i.e., ** three tenths). (Note that the array indices begin at 0 but that ** the number of dots on the sides of the die begin at 1.) ** ** @param freq the i-th element indicates the relative frequency with ** which i+1 should occur as the result of a toss ** ** @pre freq.length > 0 & for all i, freq[i] >= 0 & sum(freq) > 0 ** @post die is initialized so that, for each k satisfying 0 0 ** @post die created is such that, for each k satisfying 0