/** * Contains a name and an array of email addresses. * @author Khong Lovan * @author Elias Vafiadis * @author Anthony Nakaar * @author Wanlin Liu * version 2.0 of October, 1999 */ public class Address { //+--------+--------------------------------------------------------------- //| Fields | //+--------+ /* A name of the person who can be reached at the email address. */ Name name; /* An email addresse. */ String emailAddress; //+--------------+-------------------------------------------------------- //| Constructors | //+--------------+ /** * Create a new instance of class Address with the product of the * toString method of the Address class. * @exception if the string is not convertible. */ public Address (String fromToString) throws Exception { // Get the name // Get the index of the last comma,the one before the email address. int comma = fromToString.lastIndexOf(","); // If the index is invalid, throw an exception. if (comma == -1) { throw new Exception("Invalid"); }// if // If the index is valid, get the name object. this.name = new Name(fromToString.substring(0,comma)); // Get the address this.emailAddress = fromToString.substring(comma+1); } // Address(String) public Address (Name nme, String emailAdd){ name = nme; emailAddress = new String(); emailAddress = emailAdd; } // getName //+------------+---------------------------------------------------------- //| Extractors | //+------------+ /** * Purpose: returns the name of the user. * Parameters: no parameters. * Pre: it has to be initialized. * Post: none. * Return Type: an object. * Problems: throws no exception. */ public Name getName() { return this.name; } //getName() /** * Purpose: returns the email address of the user. * Parameters: no parameters. * Pre: it has to be initialized. * Post: none. * Return Type: a string. * Problems: throws no exception. */ public String getEmailAddress() { return this.emailAddress; } //getEmailAddress() //+-----------+--------------------------------------------------------- //| Modifiers | //+-----------+ /** * Purpose: modifies the name of the user. * Parameters: name. * Pre: it has to be initialized - there must be a name entered already. * Post: takes the original name and returns the modified one. * Return Type: none. * Problems: throws no exception. */ public void setName(Name name) { this.name = name; } //setName() /** * Purpose: modifies the email address of the user. * Parameters: emailAddress. * Pre: it has to be initialized - there must be an email address already. * Post: takes the original email address and returns the modified one. * Return Type: none. * Problems: throws no exception. */ public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } //setEmailAddress() //+--------------+------------------------------------------------------ //| Capabilities | //+--------------+ /** * Purpose: converts any information into a string. * Parameters: no parameters. * Pre: it has to be initialized. * Post: takes any information and returns the string version of it. * Return Type: a string. * Problems: throws no exception. */ public String toString(Name name) { return name.toString() + "," + emailAddress; } //toString(Name) } // class Address