/**
 * A simple encapsulation of a Person.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Person implements Ordered
{
    private int    age;    
    private String name;

    /**
     * Constructor.
     *
     * @param name  The name
     * @param age   The age
     */
    public Person(String name, int age)
    {
        this.name = name;
        this.age  = age;
    }

    /**
     * Compare the Person to the given object based on age. Return -1
     * if this is "less than" other, 0 if they are "equal", and 1 if
     * this is "greater than" other. (Required by Ordered)
     *
     * @param other  The object to compare to
     * @return -1, 0, or 1 as appropriate
     */
    public int compareTo(Ordered other)
    {
        Person   otherPerson;

        // This typecast is dangerous because, in principal, this
        // method could be passed any object that implements the
        // Ordered interface. This can be fixed using a
        // parameterized interface (as discussed later).
        otherPerson = (Person)other;

        if       (this.age  < otherPerson.age) return -1;
        else if  (this.age == otherPerson.age) return  0;
        else                                   return  1;
    }

    /**
     * Get the age.
     *
     * @return  The age
     */
    public int getAge()
    {
        return age;
    }

    /**
     * Get the name.
     *
     * @return  The name
     */
    public String getName()
    {
        return name;
    }
}
