import java.util.*;


/**
 * A simple encapsulation of a Person
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Person
{
    private int        age;    
    private String     areaCode, exchange, extension, name;
    

    /**
     * Explicit Value Constructor
     *
     * @param name      The person's name
     * @param age       The person's age
     * @param areaCode  The area code in the person's phone number
     * @param exchange  The exchange in the person's phone number
     * @param extension The extension in the person's phone number
     */
    public Person(String name, int age, 
                  String areaCode, String exchange, String extension)
    {
       this.name      = name;
       this.age       = age;
       this.areaCode  = areaCode;
       this.exchange  = exchange;
       this.extension = extension;       
    }
    

    /**
     * A "factory method" that creates a Person from
     * a String representation
     *
     * @param s    The String representation
     */
    public static Person createPerson(String s)
    {
       int                age;       
       String             areaCode, exchange, extension, name, token;
       StringTokenizer    tokenizer;


       tokenizer = new StringTokenizer(s, ",-");       

       name      = tokenizer.nextToken();
       token     = tokenizer.nextToken();
       age       = Integer.parseInt(token);
       areaCode  = tokenizer.nextToken();
       exchange  = tokenizer.nextToken();
       extension = tokenizer.nextToken();
       
       return new Person(name, age, areaCode, exchange, extension);       

    }
    

    

    /**
     * Set the phone number 
     *
     * @param areaCode  The area code in the person's phone number
     * @param exchange  The exchange in the person's phone number
     * @param extension The extension in the person's phone number
     */
    public void setPhoneNumber(String areaCode, String exchange, 
                               String extension)
    {
       this.areaCode  = areaCode;
       this.exchange  = exchange;
       this.extension = extension;       
    }

    
    /**
     * Create a String representation of this Person
     *
     * @return   The String representation
     */
    public String toString()
    {
       return name+","+age+",("+areaCode+")"+exchange+"-"+extension;       
    }
    
}
