4.6 Abstraction | 183
// Returns name as last, first, m.
publicString lastFirstMI()
{
returnlast + ", "+ first + ", "+ middle.substring(0, 1) + ".";
}
// Additional observer methods that compare an instance to another name
// Tests for equality
public booleanequals(Name otherName)
{
return first.equals(otherName.knowFirstName()) &&
middle.equals(otherName.knowMiddleName()) &&
last.equals(otherName.knowLastName());
}
// Tests for inequality
public intcompareTo(Name otherName)
{
String ourFullName;
String otherFullName;
ourFullName = (last + first + middle).toUpperCase();
otherFullName = (otherName.knowLastName() + otherName.knowFirstName() +
otherName.knowMiddleName()).toUpperCase();
returnourFullName.compareTo(otherFullName);
}
}