// BetterDate.java (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2004-10-06 File created. // 2005-05-25 Last modification. // During compilation, the files Date.java and DateDistance.java // must be in the same folder (directory) as this file. // Compile in MS-DOS window: javac BetterDate.java // Execute in MS-DOS window: java BetterDateTester class BetterDate extends Date { public BetterDate( String date_as_string ) { super( date_as_string ) ; } public String to_string_with_month_name() { String[] names_of_months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" } ; return ( names_of_months[ this_month - 1 ] + " " + this_day + ", " + this_year ) ; } public String to_american_format_string() { char saved_date_print_format = date_print_format ; date_print_format = 'A' ; String string_to_return = this.toString() ; date_print_format = saved_date_print_format ; return string_to_return ; } } class BetterDateTester { public static void main( String[] not_in_use ) { BetterDate birthday_of_einstein = new BetterDate("14.03.1879"); System.out.print( "\n Albert Einstein was born on " + birthday_of_einstein ) ; birthday_of_einstein.increment() ; System.out.print( "\n Albert was one day old on " + birthday_of_einstein.to_string_with_month_name() ) ; birthday_of_einstein.increment() ; System.out.print( "\n Albert was two days old on " + birthday_of_einstein.to_american_format_string() ) ; } }