import java.util.*; /** * The Birthday class provides functionality for an individual birthday. * * @author Dr. Ball and Student Name * @version September 18, 2006 */ public class Birthday { //instance variables: private int day; private int month; private int year; /** * No-arg constructor for the Birthday class. Sets * the default birthday to 1-1-2001 * */ public Birthday() { this.day = 1; this.month = 1; this.year = 2001; } /** * Constructor for the Birthday class that takes * three arguments. * * @param day an int * @param month an int * @param year an int */ public Birthday(int day, int month, int year) { this.day = day; this.month = month; this.year = year; } /** * setDay sets the day of the birthday. * * @param day an int */ public void setDay(int day) { this.day = day; } /** * setMonth sets the month of the birthday. * * @param month an int */ public void setMonth(int month) { this.month = month; } /** * setYear sets the year of the birthday. * * @param year an int */ public void setYear(int year) { this.year = year; } /** * getDay sets the day of the birthday. * * @return the day of the birthday */ public int getDay() { return this.day; } /** * setMonth sets the month of the birthday. * * @reutn the month of the birthday */ public int getMonth() { return this.month; } /** * setYear sets the year of the birthday. * * @return the year of the birthday */ public int getYear() { return this.year; } /** * getAge gets the age of the birthday. * * @return the age of the birthday */ public int getAge() { int age = this.getThisYear() - this.year; if (this.month > this.getThisMonth()) { age--; } else if(this.month == this.getThisMonth()) { if (this.day > this.getThisDay()) { age--; } } return age; } /** * isSeniorCitizen tests if the age of the birthday * is greater or equal to 65. If it is the method * returns true. If it is not the method returns false. * * @return if the age of the birthday is greater or equal to 65 */ public boolean isSeniorCitizen() { if (this.getAge() >= 65) return true; else return false; } /** * getThisYear returns the current year. * * @return the current year */ private int getThisYear() { Calendar cal = new GregorianCalendar(); return (int) cal.get(Calendar.YEAR); } /** * getThisYear returns the current month. * * @return the current month */ private int getThisMonth() { Calendar cal = new GregorianCalendar(); return (int) cal.get(Calendar.MONTH)+1; } /** * getThisYear returns the current day. * * @return the current day */ private int getThisDay() { Calendar cal = new GregorianCalendar(); return (int) cal.get(Calendar.DATE); } }