|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgeneseo.cs.sc.PhoneEntry
Represents entries in a simple telephone directory, with each entry containing a person's name, address, and telephone number.
This class is intended a simple model for "record" objects that can be stored in collections such as lists or trees. This class was created to support the text Algorithms & Data Structures: The Science of Computing by Doug Baldwin and Greg Scragg. All references herein to "the text" refer to that book.
| Field Summary | |
java.lang.String |
address
The street address for the person described by a telephone entry. |
java.lang.String |
name
The name of the person described by a telephone entry. |
java.lang.String |
phone
The telephone number for the person described by a telephone entry. |
| Constructor Summary | |
PhoneEntry(java.lang.String who,
java.lang.String newAddress,
java.lang.String phoneNum)
Initialize a telephone book entry with a person's name, address, and telephone number. |
|
| Method Summary | |
int |
compareTo(java.lang.Object secondEntry)
Compare two telephone entries. |
boolean |
equals(java.lang.Object secondEntry)
Determine whether two telephone entries are the same. |
int |
hashCode()
Generate a hash code for a telephone entry. |
java.lang.String |
toString()
Create a string representation of a telephone book entry. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public java.lang.String name
public java.lang.String address
public java.lang.String phone
| Constructor Detail |
public PhoneEntry(java.lang.String who,
java.lang.String newAddress,
java.lang.String phoneNum)
PhoneEntry p = new PhoneEntry( "Sue", "1 Main St", "123-4567" );
who - The person's name for the entry.newAddress - An address for this person.phoneNum - A telephone number for this person.| Method Detail |
public int compareTo(java.lang.Object secondEntry)
if ( entry1.compareTo(entry2) < 0 ) ...
compareTo in interface java.lang.ComparablesecondEntry - The phone entry to compare this one to.
secondEntry's; 0 if the names are equal; a positive number
if this entry's name is greater than secondEntry's.public boolean equals(java.lang.Object secondEntry)
if ( entry1.equals(entry2) ) ...
secondEntry - The telephone entry to compare this one to.
public int hashCode()
int code = entry.hashCode();
See chapter 14 of Algorithms and Data Structures: The Science of Computing for information on what hash codes are and why one uses them.
public java.lang.String toString()
String text = entry.toString();
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||