// ImportantBirthdays.java (c) Kari Laitinen // http://www.naturalprogramming.com // 2014-11-24 Java file created. // 2014-11-24 Last modification. // This version of the Birthdays.java program uses the new // time-related class LocalDate (available in Java 1.8 and later.) import java.util.Scanner ; import java.time.LocalDate ; class ImportantBirthdays { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; System.out.print( "\n Type in your date of birth as YYYY-MM-DD" + "\n Please, use four digits for the year" + "\n and two digits for month and day: " ) ; String date_of_birth_as_string = keyboard.nextLine() ; LocalDate date_of_birth = LocalDate.parse( date_of_birth_as_string ) ; System.out.printf( "\n You were born on a %tA", date_of_birth ) ; System.out.print( "\n Here are your days to celebrate. You are\n" ) ; int years_to_celebrate = 10 ; while ( years_to_celebrate < 80 ) { LocalDate date_to_celebrate = date_of_birth.plusYears( years_to_celebrate ) ; System.out.printf( "\n %1$d years old on %2$tF (%2$tA)", years_to_celebrate, date_to_celebrate ) ; years_to_celebrate = years_to_celebrate + 10 ; } } } /****** // The following would be another possibility to // write the first part of this program. This way the program // would accept an input date written as: 1977-7-8 keyboard.useDelimiter( "[-\\s]" ) ; int year_of_birth = keyboard.nextInt() ; int month_of_birth = keyboard.nextInt() ; int day_of_birth = keyboard.nextInt() ; LocalDate date_of_birth = LocalDate.of( year_of_birth, month_of_birth, day_of_birth ) ; *****/