public final class Rps extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
PAPER
The string representing paper.
|
static String |
ROCK
The string representing rock.
|
static String |
SCISSORS
The string representing scissors.
|
| Constructor and Description |
|---|
Rps()
Construct a hand representing rock.
|
Rps(Rps other)
Construct a hand that is a copy of the
other hand. |
Rps(String value)
Construct a hand representing the given string.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compare(Rps other)
Compares this hand to some other hand.
|
static Rps |
defeats(Rps other)
Returns the hand that defeats the given hand.
|
boolean |
equals(Object obj)
Compares this hand to the specified object.
|
String |
getValue()
Returns the string representing this hand.
|
String |
toString()
Returns the string representing this hand followed by an exclamation mark.
|
public static final String ROCK
public static final String PAPER
public static final String SCISSORS
public Rps()
public Rps(String value)
IllegalArgumentException - if value is not one of the strings
Rps.ROCK, Rps.PAPER,
Rps.SCISSORSvalue - the kind of handpublic Rps(Rps other)
other hand.other - the hand to copypublic String getValue()
equals to one of Rps.ROCK,
Rps.PAPER, Rps.SCISSORSpublic int compare(Rps other)
1 if this hand
beats the other hand; returns 0 if this hand
equals the other hand; and returns -1 if this
hand loses to the other hand.other - the hand to compare1 if this hand beats the other hand; 0 if
this hand equals the other hand; -1 if
this hand loses to the other hand.public String toString()
equals to one of Rps.ROCK,
Rps.PAPER, Rps.SCISSORS followed by
an exclamation mark.toString in class ObjectObject.toString()public boolean equals(Object obj)
true
if and only if the argument is not null and is a
Rps object that represents the same hand as this object.equals in class ObjectObject.equals(java.lang.Object)obj - the object to compare this hand againsttrue if the given object represents a Rps
object equivalent to this hand; false otherwise