/**
 * This Member class stores information about gym members and their membership.
 * 
 * @author   Michelle Lewis, Jeff Ngai
 * @version  1.0    2011-05-20
 */
public class Member
{
    private String firstName;
    private String lastName;
    private int heightInches;
    private int weightPounds;
    private int birthYear;
    private int joinedInYear;
    private int currentYear;
    
    /**
     * @param   newFirstName        = Member's first name, eg: "John"
     * @param   newLastName         = Member's last name, eg: "Doe"
     * @param   newHeightInches     = Member's height, in inches, eg: 72. Must be > 0.
     * @param   newWeightPounds     = Member's weight, in pounds (lbs), eg: 205. Must be > 0.
     * @param   newBirthYear        = Member's year of birth, eg: 1988. Must be > 1900 and <= currentYear.
     * @param   newJoinedInYear     = Member's year of joining this gym, eg: 2008. Must be > 1900 and <= currentYear.
     * @param   newCurrentYear      = Current year. eg: 2011. Must be > 1900. 
     */
    public Member(String newFirstName, 
                  String newLastName,
                  int newHeightInches,
                  int newWeightPounds,
                  int newBirthYear,
                  int newJoinedInYear,
                  int newCurrentYear)
    {
        firstName = newFirstName;
        lastName = newLastName;
        if (validateHeightInches(newHeightInches)) {
            heightInches = newHeightInches;
        } else {
            heightInches = 1;
        }
        if (validateWeightPounds(newWeightPounds)) {
            weightPounds = newWeightPounds;
        } else {
            weightPounds = 1;
        }
        if (validateCurrentYear(newCurrentYear)) {
            currentYear = newCurrentYear;
        } else {
            currentYear = 2011; 
        }
        if (validateBirthYear(newBirthYear)) {
            birthYear = newBirthYear;
        } else {
            birthYear = 1900; //arbitrary default, so the calculations work
        }
        if (validateJoinedInYear(newJoinedInYear)) {
            joinedInYear = newJoinedInYear;
        } else {
            joinedInYear = currentYear;
        }
        
    }
    
    
    //mutators
    /** @param   newFirstName        = Member's first name, eg: "John" */
    public void setFirstName(String newFirstName)
    {
        firstName = newFirstName;
    }         
    
    /** @param   newLastName         = Member's last name, eg: "Doe" */
    public void setLastName(String newLastName)
    {
        lastName = newLastName;
    }                  

    /** @param   newHeightInches     = Member's height, in inches, eg: 72. Must be > 0. */
    public void setHeightInches(int newHeightInches)
    {
        if (validateHeightInches(newHeightInches)) {
            heightInches = newHeightInches;
        } else {
            System.out.println("Error: Invalid height in inches.");
        }
    }

    /** @param   newWeightPounds     = Member's weight, in pounds (lbs), eg: 205. Must be > 0. */
    public void setWeightPounds(int newWeightPounds)
    {
        if (validateWeightPounds(newWeightPounds)) {
            weightPounds = newWeightPounds;
        } else {
            System.out.println("Error: Invalid weight in pounds (lbs).");
        }
    }
    
    /** @param   newBirthYear        = Member's year of birth, eg: 1988. Must be > 1900 and <= currentYear. */
    public void setBirthYear(int newBirthYear)
    {
        if (validateBirthYear(newBirthYear)) {
            birthYear = newBirthYear;
        } else {
            System.out.println("Error: Invalid birth year.");
        }
    }
    
    /** @param   newJoinedInYear     = Member's year of joining this gym, eg: 2008. Must be > 1900 and <= currentYear. */
    public void setJoinedInYear(int newJoinedInYear)
    {
        if (validateJoinedInYear(newJoinedInYear)) {
            joinedInYear = newJoinedInYear;
        } else {
            System.out.println("Error: Invalid year of joining gym.");
        }
    }
    
    /** @param   newCurrentYear      = Current year. eg: 2011. Must be > 1900.  */
    public void setCurrentYear(int newCurrentYear)
    {
        if (validateCurrentYear(newCurrentYear)) {
            currentYear = newCurrentYear;
        } else {
            System.out.println("Error: Invaldi current year.");
        }
    }
    
    
    //accessors
    /** @return  firstName           = Member's first name, eg: "John" */
    public String getFirstName()
    {
        return firstName;
    }
    
    /** @return  lastName            = Member's last name, eg: "Doe" */
    public String getLastName()
    {
        return lastName;
    }
    
    /** @return  fullName            = Member's full name, eg: "John Doe" */
    public String getFullName()
    {
        return firstName + " " + lastName;
    }
    
    /** @return  heightInches        = Member's height, in inches, eg: 72 */
    public int getHeightInches()
    {
        return heightInches;
    }
    
    /** @return  weightPounds        = Member's weight, in pounds (lbs), eg: 205 */
    public int getWeightPounds()
    {
        return weightPounds;
    }
    
    /** @return  weightkg            = Member's weight, in Kilograms, eg: 92.98643585 */
    public double getWeightKg()
    {
        double weightKg;
        weightKg = weightPounds * 0.45359237; //calculation to convert pounds to kilograms
        return weightKg;
    }
    
    /** @return   birthYear          = Member's year of birth, eg: 1988 */
    public int getBirthYear()
    {
        return birthYear;
    }
    
    /** @return   joinedInYear       = Member's year of joining the gym, eg: 2008 */
    public int getJoinedInYear()
    {
        return joinedInYear;
    }
    
    /** @return   currentYear        = Current year. eg: 2011 */
    public int getCurrentYear()
    {
        return currentYear;
    }
         
    
    //other methods
    /** @return                      = number of years since Member joined the gym. */
    public int calculateYearsJoined()
    {
        return currentYear - joinedInYear;
    }

    /** @return                      = age of Member in years. */
    public int calculateAge()
    {
        return currentYear - birthYear;
    }
    
    /** @return                      = age of Member at time of joining gym, in years. */
    public int calculateAgeAtJoining()
    {
        return joinedInYear - birthYear;
    }
    
    /** @return   getsDiscount       = returns true if customer receives a discount, false otherwise.
     * Requirements for discount eligibility: 
     *   - Member is over 65 years of age 
     *   OR
     *   - Member has been a member for 10 years or more
     *   OR
     *   - Member is under 12 years of age AND has been a member for 2 years or more. 
     */
    public boolean getsDiscount()
    {
        if (calculateAge() >= 65) {
            return true;
        } else if (calculateYearsJoined() >= 10) {
            return true;
        } else if ((calculateAge() < 12) && (calculateYearsJoined() >= 2)) {
            return true;
        } else {
            return false;
        }   
    }
    
    /** displays all information about Member. */
    public void displayMemberInfo()
    {
        System.out.println("Member name: " + getFullName());
        System.out.println("Member height: " + getHeightInches() + " inches");
        System.out.println("Member weight: " + getWeightPounds() + " lbs");
        System.out.println("Member birth year: " + getBirthYear());
        System.out.println("Member joined in: " + getJoinedInYear());
        System.out.println("Member gets discount: " + getsDiscount());
        System.out.println("Member's age at joining: " + calculateAgeAtJoining());
        System.out.println("Member's current age: " + calculateAge());
        System.out.println("Member for " + calculateYearsJoined() + " years.");
    }
    
    //validation methods
    /** @return     = true if valid, false otherwise. 
     * newHeightInches must be > 0
     */
    private boolean validateHeightInches(int newHeightInches)
    {
        if (newHeightInches > 0) {
            return true;
        } else {
            return false;
        }
    }
    
    /** @return     = true if valid, false otherwise. 
     * newWeightPounds must be > 0
     */
    private boolean validateWeightPounds(int newWeightPounds)
    {
        if (newWeightPounds > 0) {
            return true;
        } else { 
            return false;
        }
    }
    
    /** @return     = true if valid, false otherwise. 
     * newCurrentYear must be > 1900
     */
    private boolean validateCurrentYear(int newYear)
    {
        if ((newYear > 1900)) {
            return true;
        } else {
            return false;
        }
    }
    
    /** @return     = true if valid, false otherwise. 
     * newBirthYear must be > 1900 
     * newBirthYear must be <= currentYear
     */
    private boolean validateBirthYear(int newYear)
    {
        if ((newYear > 1900) && (newYear < currentYear)) {
            return true;
        } else {
            return false;
        }
    }
        
    /** @return     = true if valid, false otherwise. 
     * newJoinedInYear must be > 1900 
     * newJoinedInYear must be <= currentYear
     */
    private boolean validateJoinedInYear(int newYear)
    {
        if ((newYear > 1900) && (newYear <= currentYear) && (newYear > birthYear)) {
            return true;
        } else {
            return false;
        }
    }
}
