FileDocCategorySizeDatePackage
Die.javaAPI DocExample580Mon Feb 13 12:32:02 GMT 2006None

Die.java

import java.util.*;
import java.io.*;

public class Die implements Serializable {

  private int face = 1;
  Random shooter = new Random();

  public Die(int face) {
    if (face < 1 || face > 6) throw new IllegalArgumentException();
    this.face = face;
  }

  public final int getFace() {
    return this.face;
  }

  public void setFace(int face) {
    if (face < 1 || face > 6) throw new IllegalArgumentException();
    this.face = face;
  }

  public int roll() {
    this.face = (Math.abs(shooter.nextInt()) % 6) + 1;
    return this.face;
  }
}