/**
   A class for representing a person.
 
   @author Yves Lesperance
*/

public class Person
{
	// instance attributes

	private String name;
	private int age;
	   
	//constructors
	
	/**
    This constructor constructs a person object having the given name 
    and age.

    @param name The name of the person.
    @param age The age of the person.
    @pre. age >= 0
	 */
	public Person(String name, int age)
	{
		this.setName(name);
		this.setAge(age);
	}
	
    /**
    This default constructor constructs a person with an unknown name 
    and age 0.
 */
	public Person()
	{
		this("UNKNOWN",0);
	}

	/**
    This copy constructor constructs a person with the same 
    name and age as the given person.

    @param person The person to be copied.
 */
 public Person(Person person)
 {
	this(person.getName(), person.getAge());
 }

	/**
	 * Returns the name of this person.
	 * 
	 * @return The name of this person.
	 */
	public String getName()
	{
		return this.name;
	}

	/**
	 * 	Sets the name of this person to the given name.

	 * @param name The name to set for the person.
	 */
	public void setName(String name)
	{
		this.name = name;
	}

	/**
	 * Returns the age of this person.
	 * 
	 * @return The age of this person.
	 */
	public int getAge()
	{
		return this.age;
	}

	/**
	Sets the age of this person to the given age.
	
	@param age The new age to set for this person.
    @pre. width >= 0
	 */
	public void setAge(int age)
	{
		this.age = age;
	}

	/**
	Sets the name and age of this person to the given name and age.
	
	@param name The name to set for the person.
	@param age The new age to set for this person.
    @pre. width >= 0
	 */

	public void setNameAndAge(String n, int a)
	{
	   this.setName(n);
	   this.setAge(a);
	}

	/**
    Returns a string representation of this person. 
    For example, the string representation of new Person("John", 18) 
    is "Person named John and aged 18".

    @return A string representation of this person.
    */
    public String toString()
    {
    	return "Person named " + this.getName() + " and aged " + this.getAge();
    }

	/**
	 * Determines whether the argument is equal to this person.
	 * This holds if they have identical names.
	 * 
	 * @param object The object to be compared to this person.
	 * 
	 * @return Whether the argument is equal to this person.
	 */
  	public boolean equals(Object object)
   	{
   		boolean equal;
   		if (object != null && this.getClass() == object.getClass())
   		{
   			Person other = (Person) object;
   			equal = (this.getName().equals(other.getName()));
   		}
   		else
   		{
   			equal = false;
   		}
   		return equal;
   	}

	/**
	Increments the age of this person by one.
	
	 */

	public void incrementAge()
	{
	   this.setAge(this.getAge()+1);
	}

}
