public class Coin extends Object implements Comparable<Coin>
Modifier and Type | Field and Description |
---|---|
static Coin |
DIME
A coin representing a Canadian dime.
|
static Coin |
LOONIE
A coin representing a Canadian $1 coin.
|
static Coin |
NICKEL
A coin representing a Canadian nickel.
|
static Coin |
PENNY
A coin representing a Canadian penny.
|
static Coin |
QUARTER
A coin representing a Canadian quarter.
|
static Coin |
TOONIE
A coin representing a Canadian $2 coin.
|
Constructor and Description |
---|
Coin(Coin c)
Initializes this coin to have the same value as the
specified coin.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Coin other)
Compares this coin to the specified coin.
|
boolean |
equals(Object obj)
Compares this coin to another coin returning true if and
only if the specified object is a Coin with the same
value as this coin.
|
int |
getValue()
Returns the value of this coin in Canadian cents.
|
int |
hashCode()
Returns a hash code for this coin.
|
String |
toString()
Returns a string describing this coin.
|
public static final Coin PENNY
public static final Coin NICKEL
public static final Coin DIME
public static final Coin QUARTER
public static final Coin LOONIE
public static final Coin TOONIE
public Coin(Coin c)
c
- a coinpublic int getValue()
public int hashCode()
public boolean equals(Object obj)
public String toString()
"penny", "nickel", "dime",
"quarter", "loonie", "twoonie"
.public int compareTo(Coin other)
this.getValue() - other.getValue()
.compareTo
in interface Comparable<Coin>
other
- a coin to compare