// ISODateCalendarsGenerator.java Copyright (c) Kari Laitinen // http://www.naturalprogramming.com // 2016-01-26 File created. // 2020-03-11 Last modification /* The Gregorian Calendar, that most countries of the world use, is such that it actually consists of 14 different types of calendars, which can be denoted with numbers from 1 to 14 in the following way: 1 Non-Leap Year starting with Monday 2 Non-Leap Year starting with Tuesday 3 Non-Leap Year starting with Wednesday 4 Non-Leap Year starting with Thursday 5 Non-Leap Year starting with Friday 6 Non-Leap Year starting with Saturday 7 Non-Leap Year starting with Sunday 8 Leap Year starting with Monday 9 Leap Year starting with Tuesday 10 Leap Year starting with Wednesday 11 Leap Year starting with Thursday 12 Leap Year starting with Friday 13 Leap Year starting with Saturday 14 Leap Year starting with Sunday This program prints initialization data for arrays that represent the above calendars. The output data of this program is used in ISODate.java. */ import java.time.* ; // for classes LocalDate, Period import java.time.temporal.WeekFields ; import java.util.Scanner ; class ISODateCalendarsGenerator { public static void print_calendar_data( int given_year ) { int month = 1 ; int day = 1 ; LocalDate date_to_increment = LocalDate.of( given_year, month, day ) ; System.out.print( "\n {" ) ; while ( date_to_increment.getYear() == given_year ) { System.out.print( "\n { " ) ; while ( date_to_increment.getMonthValue() == month ) { if ( day < date_to_increment.lengthOfMonth() ) { System.out.print( date_to_increment.getDayOfWeek().getValue() + "," ) ; } else { // No comma after the last element in initialization data. System.out.print( date_to_increment.getDayOfWeek().getValue() + "" ) ; } day ++ ; date_to_increment = date_to_increment.plusDays( 1 ) ; } if ( month < 12 ) { System.out.print( " }," ) ; } else { System.out.print( " }" ) ; } day = 1 ; month ++ ; } System.out.print( "\n }," ) ; } public static void main( String[] not_in_use ) { print_calendar_data( 2001 ) ; // Non-leap, start Monday print_calendar_data( 2002 ) ; // Non-leap, start Tuesday print_calendar_data( 2003 ) ; // Non-leap, start Wednesday print_calendar_data( 2009 ) ; print_calendar_data( 2010 ) ; print_calendar_data( 2011 ) ; print_calendar_data( 2006 ) ; // Non-leap, start Sunday print_calendar_data( 2024 ) ; // Leap year, start Monday print_calendar_data( 2008 ) ; // Leap year, start Tuesday print_calendar_data( 2020 ) ; // Leap year, start Wednesday print_calendar_data( 2004 ) ; print_calendar_data( 2016 ) ; print_calendar_data( 2028 ) ; print_calendar_data( 2012 ) ; // Leap year, start Sunday } }