// A class that implements the Person interface. // Barry Cornelius, 19 June 2000 import java.util. StringTokenizer; public class PersonImpl implements Person { private String iName; private Date iDateOfBirth; private String iPhoneNumber; private double iHeight; public PersonImpl() { this("", new DateImpl(), "", 0.0); } public PersonImpl(final Person pPerson) { final PersonImpl tPersonImpl = (PersonImpl)pPerson; iName = tPersonImpl.iName; iDateOfBirth = new DateImpl(tPersonImpl.iDateOfBirth); iPhoneNumber = tPersonImpl.iPhoneNumber; iHeight = tPersonImpl.iHeight; } public PersonImpl(final String pName, final Date pDateOfBirth, final String pPhoneNumber, final double pHeight) { iName = pName; iDateOfBirth = new DateImpl(pDateOfBirth); iPhoneNumber = pPhoneNumber; iHeight = pHeight; } //BJCHEREFIRST public PersonImpl(final String pPersonString) { try { final StringTokenizer tTokens = new StringTokenizer(pPersonString, "%"); iName = tTokens.nextToken(); final String tDateOfBirthString = tTokens.nextToken(); iDateOfBirth = new DateImpl(tDateOfBirthString); iPhoneNumber = tTokens.nextToken(); String tHeightString = tTokens.nextToken(); if (tHeightString.equals("")) { tHeightString = "0.0"; } iHeight = Double.parseDouble(tHeightString); } catch(final Exception pException) { iName = ""; iDateOfBirth = new DateImpl(); iPhoneNumber = ""; iHeight = 0.0; throw new IllegalArgumentException(); } } public String getName() { return iName; } public Date getDateOfBirth() { return new DateImpl(iDateOfBirth); } public String getPhoneNumber() { return iPhoneNumber; } public double getHeight() { return iHeight; } //BJCHERECONT public void setName(final String pName) { iName = pName; } public void setDateOfBirth(final Date pDateOfBirth) { iDateOfBirth = new DateImpl(pDateOfBirth); } public void setPhoneNumber(final String pPhoneNumber) { iPhoneNumber = pPhoneNumber; } public void setHeight(final double pHeight) { iHeight = pHeight; } public boolean equals(final Object pObject) { if ( pObject==null || getClass()!=pObject.getClass() ) { return false; } return iName.equals(((PersonImpl)pObject).iName); } public int hashCode() { return 0; } public int compareTo(final Object pObject) { final PersonImpl tPersonImpl = (PersonImpl)pObject; return iName.compareTo(tPersonImpl.iName); } public String toString() { return iName + "%" + iDateOfBirth + "%" + iPhoneNumber + "%" + iHeight; } }