// EventsOLD.cs (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2002-11-25 Java file created. // 2005-05-10 Last modification. // This is an old version of the Events.java program. // Class ArrayList is exploited here in "raw" old-fashioned way. // An iterator is used to access the elements of the ArrayList // array. Iterators are not, however, old-fashioned things in Java. // When this program is compiled, Date.java must be in the same // folder (directory) together with this file. import java.util.ArrayList ; import java.util.Collections ; import java.util.Iterator ; class Event extends Date implements Comparable { protected String event_description ; public Event( int day_of_event, int month_of_event, int year_of_event, String given_event_description ) { this_day = day_of_event ; this_month = month_of_event ; this_year = year_of_event ; event_description = given_event_description ; } public String toString() { Date date_of_event = new Date( this_day, this_month, this_year, date_print_format ) ; return ( date_of_event + " " + event_description ) ; } public int compareTo( Object object_to_compare_to ) { Event event_to_compare_to = (Event) object_to_compare_to ; int comparison_result = 0 ; // Events of the same date. if ( this.is_earlier_than( event_to_compare_to ) ) { comparison_result = -1 ; // "this" has earlier date. } else if ( this.is_later_than( event_to_compare_to ) ) { comparison_result = 1 ; // "this" has later date. } return comparison_result ; } } class EventsOLD { public static void main( String[] not_in_use ) { Event birth_of_lennon = new Event( 9, 10, 1940, "John Lennon was born.") ; Event birth_of_einstein = new Event( 14, 3, 1879, "Albert Einstein was born." ) ; ArrayList list_of_events = new ArrayList() ; list_of_events.add( birth_of_lennon ) ; list_of_events.add( birth_of_einstein ) ; list_of_events.add( new Event( 8, 12, 1980, "John Lennon was shot in New York." ) ) ; System.out.print( "\nEvents of list_of_events: \n" ) ; Iterator event_on_list = list_of_events.iterator() ; while ( event_on_list.hasNext() ) { System.out.print( "\n " + event_on_list.next() ) ; } ArrayList another_event_list = new ArrayList() ; another_event_list.add( 0, new Event( 1, 6, 1926, "Marilyn Monroe was born." ) ) ; another_event_list.add( 0, new Event( 5, 8, 1962, "Marilyn Monroe died." ) ) ; another_event_list.add( new Event(15, 8, 1769, "Napoleon Bonaparte was born." ) ) ; another_event_list.add( new Event(25,10, 1881, "Pablo Picasso was born." ) ) ; System.out.print( "\n\nEvents of another_event_list: \n" ) ; event_on_list = another_event_list.iterator() ; while ( event_on_list.hasNext() ) { System.out.print( "\n " + event_on_list.next() ) ; } Collections.sort( list_of_events ) ; Collections.sort( another_event_list ) ; list_of_events.addAll( 0, another_event_list ) ; System.out.print( "\n\nEvents of list_of_events: \n" ) ; event_on_list = list_of_events.iterator() ; while ( event_on_list.hasNext() ) { System.out.print( "\n " + event_on_list.next() ) ; } } }