public abstract class Martian extends Object implements Comparable<Martian>
Modifier and Type | Field and Description |
---|---|
private int |
id
Every
Martian has an id which is simply an integer. |
private int |
volume
Every
Martian has a volume which is simply an integer. |
Constructor and Description |
---|
Martian(int id,
int volume)
Creates a
Martian with the specified id and volume . |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Martian m)
Implements Java's
compareTo so that Martian s (either red or green) are compared based on
their id 's which results in the usual ascending sorted order. |
boolean |
equals(Object o)
Returns
true if the input is a Martian whose id is the same
is this Martian 's id . |
int |
getId()
Returns the
id for this Martian . |
int |
getVolume()
Returns the
volume for this Martian . |
abstract int |
power()
Returns the power of this
Martian . |
void |
setVolume(int volume)
Set the
volume for this Martian . |
abstract String |
speak()
Returns a string that represents this
Martian speaking. |
String |
toString()
Returns a string in this exact format:
|
private int id
Martian
has an id which is simply an integer.private int volume
Martian
has a volume which is simply an integer.public Martian(int id, int volume)
Martian
with the specified id
and volume
.id
- volume
- public int compareTo(Martian m)
compareTo
so that Martian
s (either red or green) are compared based on
their id
's which results in the usual ascending sorted order.compareTo
in interface Comparable<Martian>
public boolean equals(Object o)
true
if the input is a Martian
whose id
is the same
is this Martian
's id
.equals
in class Object
o
- The object being compared to this object.true
if this Martian
's id
is the same as the input's id
.public int getId()
id
for this Martian
.Martian
.public int getVolume()
volume
for this Martian
.Martian
.public abstract int power()
Martian
.Martian
.public void setVolume(int volume)
volume
for this Martian
.volume
- The new volume
public abstract String speak()
Martian
speaking.Martian
speaking.public String toString()
id=X, vol=Ywhere X is the
id
, Y is the volume
. Note that RedMartian and GreenMartian's toString
can use these values by calling: super.toString()
.toString
in class Object