// Wuerfel.java MM 2009 /** * Wuerfel min .. max. */ public class Wuerfel { /* ------------------------------------------------- */ // Attribute /** * Minimale Augenzahl. */ private int min = 1; /** * Maximale Augenzahl. */ private int max = 6; /** * Aktuelle Augenzahl. */ private int augen; /* ------------------------------------------------- */ // set-Methode /** * Setzt Attribute. * @param minZahl minimale Augenzahl * @param maxZahl maximale Augenzahl */ public void setWuerfel( int minZahl, int maxZahl) { if( maxZahl < minZahl) { min = maxZahl; // vertauschen max = minZahl; } else { min = minZahl; max = maxZahl; } wuerfeln(); } /* ------------------------------------------------- */ // get-Methode /** * Liest aktuelle Augenzahl. * @return Augenzahl */ public int getAugen() { return augen; } /* ------------------------------------------------- */ // service-Methode /** * Wuerfeln, * erzeugt zufällig ganze Zahl zwischen min und max. * @return Augenzahl */ public int wuerfeln() { augen = (int)(Math.random() * ( max - min + 1)) + min; return augen; } }