public class BoggleDie extends Object
Q
. Instead
of using the letter Q
, the string QU
is used to
reflect the fact that Q
is almost always followed by
U
in English words.Constructor and Description |
---|
BoggleDie(BoggleDie other)
Construct an independent copy of an existing die.
|
BoggleDie(String letters)
Construct a die where the sides are lettered according to the characters in
the given string converted to uppercase.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares this die to the specified object.
|
String |
getValue()
Gets the current face value as a string.
|
SortedMap<Integer,String> |
getValueMap()
Returns the mapping of faces to letters for this die.
|
int |
hashCode()
Returns a hash code for this die.
|
void |
roll()
Rolls the die to a new random face value.
|
String |
toString()
Returns a string representation of this die.
|
public BoggleDie(String letters)
new BoggleDie("aAeEgN");
would construct a die where the sides are lettered "A"
,
"A"
, "E"
, "E"
, "G"
, and
"N"
. If one of the characters in the string is
'Q'
then the corresponding die face is labelled with the
string "QU"
instead.
The mapping of the letters to the die faces is unspecified; all that is guaranteed is that each letter in the given string is mapped to one and only one face of the die.
IllegalArgumentException
- if the characters in the given string are not all in the range
[a-zA-Z]
.IllegalArgumentException
- if the length of the given string is not exactly 6
.letters
- a string of length 6
containing the letters used to
label the sides of the diepublic BoggleDie(BoggleDie other)
other
- the die to copypublic void roll()
public String getValue()
1
with the exception of the string "QU"
.public SortedMap<Integer,String> getValueMap()
Integer
values 1
through
6
, and the returned map is sorted on its keys (the face
numbers). For example, the die with faces:
1, 2, 3, 4, 5, 6
having letters:
C, M, I, O, U, T
would return the map whose toString
method would produce the
following string:
{1=C, 2=M, 3=I, 4=O, 5=U, 6=T}
Clients are unable to modify the mapping of faces to letters using the returned map; i.e., modifying the returned map has no effect on the die.
public int hashCode()
hashCode
in class Object
Object.hashCode()
public boolean equals(Object obj)
true
if and only if all of the following are true
:
null
BoggleDie
referenceequals
Note that two dice can be equals
if their mappings of faces to
letters are different; as long as both dice contain the exact same letters
it is possible for the dice to be equals
.
equals
in class Object
Object.equals(java.lang.Object)
obj
- the object to comparetrue
if the two dice are equal (see above), and
false
otherwisepublic String toString()
1, 2, 3, 4, 5, 6
having letters:
C, M, I, QU, U, T
has the string representation C, M, I, QU, U, T
.
toString
in class Object
Object.toString()