// This program makes tNoelDate, a variable of the class type Date, // refer to an object of class Date representing Christmas Day 2000. // It then makes tOtherDate refer to another Date object, // and then uses both == and equals to compare the two variables. // Barry Cornelius, 19 June 2000 import java.io. BufferedReader; import java.io. InputStreamReader; import java.io. IOException; public class NoelProg { public static void main(final String[] pArgs) throws IOException { final Date tNoelDate = new Date(2000, 12, 25); System.out.println("tNoelDate is: " + tNoelDate); final BufferedReader tKeyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Type in the date, e.g., 2000-12-25: "); System.out.flush(); final String tOtherDateString = tKeyboard.readLine(); final Date tOtherDate = new Date(tOtherDateString); System.out.println("tOtherDate is: " + tOtherDate); System.out.println("tUsingOperator: " + (tNoelDate==tOtherDate)); System.out.println("tNoelDate.equals: " + tNoelDate.equals(tOtherDate)); System.out.println("tOtherDate.equals: " + tOtherDate.equals(tNoelDate)); System.out.println("tNoelDate.iIsLeap: " + iIsLeap(tNoelDate)); System.out.println("tOtherDate.iIsLeap: " + iIsLeap(tOtherDate)); } private static boolean iIsLeap(final Date pDate) { int tYear = pDate.getYear(); return (tYear%400==0) || (tYear%4==0 && tYear%100!=0); } }