package addressbook;
public class AddressBook
// This class defines an address book, consisting of 10 parts
{
// Class constant
final String PUNCT = ", "; // Punctuation for formatting
// Instance variable
String first;
String middle;
String last;
String homeadd;
String homeph;
String busadd;
String busph;
String faxnum;
String cellnum;
String pagenum;
// Constructors
public AddressBook(String firstName, String middleName, String lastName, String homeAddress, String homePhone, String businessAddress, String businessPhone, String faxNumber, String cellNumber, String pagerNumber)
// Init an Address Book object with all addressbook fields
{
first=firstName;
middle=middleName;
last=lastName;
homeadd=homeAddress;
homeph=homePhone;
busadd=businessAddress;
busph=businessPhone;
faxnum=faxNumber;
cellnum=cellNumber;
pagenum=pagerNumber;
}
// Basic observers that return the value of each feild
public String knowFirstName ()
{
return first;
}
public String knowMiddleName ()
{
return middle;
}
public String knowLastName ()
{
return last;
}
public String knowHomeAddress ()
{
return homeadd;
}
public String knowHomePhone ()
{
return homeph;
}
public String knowBusinessAddress ()
{
return busadd;
}
public String knowBusinessPhone ()
{
return busph;
}
public String knowFaxNumber ()
{
return faxnum;
}
public String knowCellNumber ()
{
return cellnum;
}
public String knowPagerNumber ()
{
return pagenum;
}
// Additional observers for first middle last format
public String firstMidLast ()
{
return first + " " + middle + " " + last;
}
public String lastFirstMid ()
{
return last + PUNCT + first + " " + middle;
}
// Equals and CompareTo methods
public boolean equals (AddressBook otherName)
{
return
first.equals (otherName.first) &&
middle.equals (otherName.middle) &&
last.equals (otherName.last);
}
public int compareTo (AddressBook otherName)
{
int result;
result = last.toUpperCase().compareTo(otherName.last.toUpperCase());
if (result != 0)
return result;
else
{
result = first.toUpperCase().compareTo(otherName.first.toUpperCase());
if (result != 0)
return result;
else
return
result = middle.toUpperCase().compareTo(otherName.middle.toUpperCase());
}
}
}
No comments:
Post a Comment