Complete a program which determines if a year is a leap year.
/*************************************************************************** * Complete this class which determines if a year is a leap year or not. ***************************************************************************/ public class LeapYear { private int year; /** * Creates a Year object to test whether a particular year is a leap year. * @param aYear is the year to be tested */ public LeapYear(int aYear) { year = aYear; } /** * Method to determine if a year is a leap year. * @return boolean true year is a leap year * * A leap year is a year in which an extra day is added to the calendar * in order to synchronize it with the seasons. * In the Gregorian calendar currently in use worldwide, there is a leap year * every year divisible by four. * * Beginning in 1582 an adjustment was made to the calculation. * * Years divisible by 100 are leap years only if they are divisible by 400 as well. * So, in the last millennium, 1600 and 2000 were leap years, but 1700, 1800 * and 1900 were not. * * Note: 1500 WAS a leap year since it is divisible by 4 and was before 1582. */ public boolean isLeapYear() { // <<<<<<<<<<<<<<<<<<<<< COMPLETE THE CODE >>>>>>>>>>>>>>>>>>>> } /** * Method which calls the isLeapYear() method, * then returns a String which states that * the given year is or is not a leap year. */ public String toString() { // <<<<<<<<<<<<<<<<<<<<< COMPLETE THE CODE >>>>>>>>>>>>>>>>>>>> } }
/** * This is a tester class driver for Year class * * The year 2008 is a leap year. * The year 1500 is a leap year. * The year 1600 is a leap year. * The year 1900 is NOT a leap year. * The year 2000 is a leap year. * The year 2004 is a leap year. * The year 2104 is a leap year. * The year 2100 is NOT a leap year. * The year 1206 is NOT a leap year. * */ public class LeapYearTester { public static void main(String[] args) { LeapYear yearA = new LeapYear(2008); System.out.println(yearA.toString()); LeapYear yearB = new LeapYear(1500); System.out.println(yearB.toString()); LeapYear yearC = new LeapYear(1600); System.out.println(yearC.toString()); LeapYear yearD = new LeapYear(1900); System.out.println(yearD.toString()); LeapYear yearE = new LeapYear(2000); System.out.println(yearE.toString()); LeapYear yearF = new LeapYear(2004); System.out.println(yearF.toString()); LeapYear yearG = new LeapYear(2104); System.out.println(yearG.toString()); LeapYear yearH = new LeapYear(2100); System.out.println(yearH.toString()); LeapYear yearI = new LeapYear(1206); System.out.println(yearI.toString()); } }