/* * @topic T00865 Using Comparable interface to sort objects * @brief Die class */ package hw7demo; public class Die { static final int DEFAULT_SIDE_COUNT = 6; private int dieSideCount; private int faceValue; // constructors public Die() { dieSideCount = DEFAULT_SIDE_COUNT; roll(); // immediately roll } public Die( int dieSideCount ) { this.dieSideCount = dieSideCount; roll(); // immediately roll } // the user wants to set the face value public Die( int dieSideCount, int faceValue ) { this.dieSideCount = dieSideCount; // TODO -- verify that the faceValue is valid this.faceValue = faceValue; } public int roll() { faceValue = 1 + (int) ( Math.random() * dieSideCount ); return faceValue; } }//class Die