/** * Write a description of class Domino here. * * @author (your name) * @version (a version number or a date) */ public class Domino { // number of spots on left end of the domino private int leftSpots; // number of spots on left end of the domino private int rightSpots; // value of this domino (depends on the game being played) private int value; /** * Constant denoting a single spot */ public static final int ONE = 1; /** * Constant denoting the text label for a single spot on one end. */ public static final String ONE_LABEL = "One"; /** * The primary constructor that creates a new domino with the specified * number of spots on each end. * @param numSpots1 the non-negative number of spots on one end of the domino * @param numSpots2 the non-negative number of spots on the other end of the domino */ public Domino(int lSpots, int rSpots) { // assign the specified parameters to the corresponding instance variables // if either given value is negative set to -1 as a signal of bad value if (lSpots < 0 || rSpots < 0) { leftSpots = -1; rightSpots = -1; //again we use -1 as a signal of bad domino value = -1; } else { leftSpots = lSpots; rightSpots = rSpots; value = leftSpots + rightSpots; } } /** * Checks whether the domino supplied as a paramter has an end that matches either end of the domino * from which the method is called. * * @param domino a domino to evaluate for a matching end * @return True if the two dominoes have an end with the same number of spots, otherwise false. */ public boolean isMatch(Domino dom) { //check to make sure the paramter isn't null if (dom == null) return false; // check for equality in the four possible cases of a match and return true if any is true if (this.leftSpots == dom.leftSpots || this.leftSpots == dom.rightSpots || this.rightSpots == dom.leftSpots || this.rightSpots == dom.rightSpots) return true; else return false; } }