Data Type Class

Synopsis

Create the data type class Domino as required by the sample driver program A02 (provided). It must override the toString method, and use the Comparable and Comparator interfaces to make Domino objects sortable. It must throw IllegalArgumentExceptions as appropriate.

Your class must demonstrate good design as well as proper function. That includes using appropriate access and other modifiers, and including appropriate javadoc commentary. All course style rules must be followed.

Details

This assignment requires you to create a data type class. The class represents a domino -- a tile with two ends, and a small integer number on each end. Dominoes come in different size sets, the smallest standard size being "double six" (the numbers on each end run from zero to six), and the largest standard size being "double eighteen" (the numbers on each end being zero to eighteen). The class you are creating represents a single domino, not a set. The program I give you creates and manipulates a set of dominoes.

As mentioned above, each domino has two numbers. In general one number will be higher than the other, tho' the two may be equal.

Domino objects are immutable, meaning they have no setters.

Your domino class has the following methods:

It also has one constructor, which takes two integer values and creates a Domino object with those two numbers. The numbers must be in the range 0 to 99 (inclusive).

Objects of your class must sort naturally by the higher number (highest numbers first) with ties broken by the lower number. For example, [11| 5] comes before both [10| 9] (because 11 > 10) and [11| 3] (because 11 == 11 and 5 > 3). On the other hand, [11| 5] comes after [12| 0] (because 11 < 12).

Finally, your class must include a Comparator<Domino> named BY_SUM, which allows Domino objects to be sorted by the sum of their numbers. When sorted using this Comparator, [11| 5] comes after [10| 9] (because 11 + 5 < 10 + 9), but before both [11| 3] (because 11 + 5 > 11 + 3) and [12| 0] (because 11 + 5 > 12 + 0).