public abstract class Contact extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<Contact>
Modifier and Type | Field and Description |
---|---|
static int |
FIRST_NUMBER
The class generates contact numbers serially starting
from this value.
|
Constructor and Description |
---|
Contact(java.lang.String name,
java.lang.String address)
Construct a contact having the given name
and address and assign a unique number to it.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Contact other)
Compares this object with the specified object for order.
|
boolean |
equals(java.lang.Object other)
Test the equality of contacts.
|
java.lang.String |
getAddress()
Determine the address of
this contact. |
static int |
getLastContactNumber()
Determine the number of the last-constructed
contact.
|
java.lang.String |
getName()
Determine the name of
this contact. |
int |
getNumber()
Determine the number of
this contact. |
int |
hashCode()
Compute a hash code for
this Contact. |
void |
setAddress(java.lang.String address)
Change the address of
this contact. |
void |
setName(java.lang.String name)
Change the name of
this contact. |
java.lang.String |
toString()
Construct a string representation of
this contact. |
public static final int FIRST_NUMBER
public Contact(java.lang.String name, java.lang.String address)
FIRST_NUMBER
.name
- the name of the contact.address
- the address of the contact.java.lang.RuntimeException
- if the name
or the address is null.public java.lang.String getName()
this
contact.this
contact.public java.lang.String getAddress()
this
contact.this
contact.public int getNumber()
this
contact.this
contact.public void setName(java.lang.String name)
this
contact.name
- the new name.java.lang.RuntimeException
- if the parameters is null.public void setAddress(java.lang.String address)
this
contact.address
- the new addressjava.lang.RuntimeException
- if the parameters is null.public static int getLastContactNumber()
public java.lang.String toString()
this
contact.toString
in class java.lang.Object
xxx name
", where
xxx
is the contact number and
name
is its name.public boolean equals(java.lang.Object other)
this
contact if
it is instantiated from the same class as this
one
and has the same number.equals
in class java.lang.Object
other
- a reference to the object to test equality with.true
if other
is not null
and it points to an object that is equal (as defined above) to
this
object. The return is false
otherwise.public int hashCode()
this
Contact.hashCode
in class java.lang.Object
public int compareTo(Contact other)
compareTo
in interface java.lang.Comparable<Contact>
other
- the Object to compare to.compareTo(String)
in String
when invoked on the toString
of this item.