// A class that implements the Person interface.
// Barry Cornelius, 13th November 1998
// Updated on 30th January 1999 to replace DateOfBirth aliasing by copying 
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 String pName, final Date pDateOfBirth,
                     final String pPhoneNumber, final double pHeight) 
   {
      iName = pName; 
      iDateOfBirth = new DateImpl(pDateOfBirth.toString()); 
      iPhoneNumber = pPhoneNumber;
      iHeight = pHeight;
   }
   public PersonImpl(final String pPersonString)
   {
      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 = new Double(tHeightString).doubleValue();
   }
   public String getName()        { return iName; }
   public Date getDateOfBirth(){ return new DateImpl(iDateOfBirth.toString()); }
   public String getPhoneNumber() { return iPhoneNumber; }
   public double getHeight()      { return iHeight; }
   public void setName(final String pName)
   { iName = pName; }
   public void setDateOfBirth(final Date pDateOfBirth)
   { iDateOfBirth = new DateImpl(pDateOfBirth.toString()); }
   public void setPhoneNumber(final String pPhoneNumber)
   { iPhoneNumber = pPhoneNumber; }
   public void setHeight(final double pHeight)
   { iHeight = pHeight; }
   public boolean equals(final Object pObject)
   {
      if ( ! (pObject instanceof PersonImpl) )
      {
         return false;
      }
      return iName.equals(((PersonImpl)pObject).iName);
   }
   public int hashCode()          { return iName.hashCode(); }
   public String toString()
   {
      return iName + "%" + iDateOfBirth + "%" + iPhoneNumber + "%" + iHeight;
   }
}
