/*
/*
Online Java - IDE, Code Editor, Compiler
Online Java is a quick and easy tool that helps you to build, compile, test your programs
online.
*/

public class Main
{
    static int year; // this is the year
    static String yearString;
    static String finalDate; //this will be in format DD/MM/YYYY
    static String finalDatePalindrome; // this will be DDMMYYYY to ensure palindrome check can be complete
    static Object days; //object since it is extracted from enum value
    static Object month; //object since it is extracted from enum value
    static Object objectLeapYearFebruaryDays; //extracted from enum value
    static int intLeapYearFebruaryDays; //stores 29 on leap year
    static boolean leapYear; //check if leap year
    static String temp;
    static Object prefixZero = "0"; //added to form DD for days less than 10
    static int daysMonth; //uses days Object from above
    static int monthcount; // ensures main do while loop is constrained
    static String formattedMonth; //obtain correct format such 01, 02...
    static int ddInt; // used to initiate starting date in for loop...
    static int mmInt; // used to select month and set month
    static String ddString; // linked to ddInt
    static String mmString; //linked to mmInt
    static boolean processedFirstMonth=false; // used to control ddInt... Once first month is complete,
    //start date ddInt each month will be 1
    //method call to check if palindrome

    public static void checkPalindrome(String finalDate, String finalDatePalindrome)
    {
        //System.out.println("CHECKING!");
        String reverseString;
        int j=0;
        StringBuffer sb = new StringBuffer();
        
        for (int i=finalDatePalindrome.length()-1; i>=0; i--)
        {
            sb.append(finalDatePalindrome.charAt(i));
            j++;
        }
        reverseString=sb.toString();
        
        if(finalDatePalindrome.equalsIgnoreCase(reverseString))
        {
            System.out.println("Palindrome");
            System.out.println(finalDate); // Date will be outputted DD/MM/YYYY
        }
    }
    
    // enum containing the days, MM
    
    enum Months
    {
        JAN (31,1),
        FEB(28,2),
        MAR(31,3),
        APR(30,4),
        MAY(31,5),
        JUN(30,6),
        JUL(31,7),
        AUG(31,8),
        SEPT(30,9),
        OCT(31,10),
        NOV(30,11),
        DEC(31,12);

        public int days;
        public int month;
        
        Months (int days, int month)
        {
            this.days=days;
            this.month=month;
        }
    }
    
    public static void main(String[] args) 
    {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        palindromicDates("01/01/2020", 100);
    }
    
    public static void palindromicDates (String date, int years)
    {
        int startPos = date.length()-4; // this is marker to start the year YYYY
        createDate(startPos, date, years);
    }
    
    public static void createDate(int startPos, String date, int years)
    {
        yearString = date.substring(startPos, date.length());
        year = Integer.valueOf(yearString);
        ddString = date.substring(0,2);
        ddInt = Integer.valueOf(ddString);
        mmString = date.substring(3,5);
        mmInt = Integer.valueOf(mmString)-1; // this is reduced by 1 since it will be used in contexts
        // involving zero index notation.
        boolean newYearRollOver=false; // default value
        
        for (int i=0; i<=years; i++)
        {
            System.out.println(year); // to ensure memory limit not exceeded, this is only statement printed to Screen
            //with exception of if palindrome successful
            newYearRollOver=false;
            leapYear=false;
            monthcount=0;
            
            do
            {
                // processing the months in the enum
                
                for (Months m: Months.values())
                {
                    switch (mmInt) // this is used to get the correct MM format.
                    // In hindsight, perhaps both parameters in JAN (31,1) should have been string
                    {
                        case 0:
                        formattedMonth = "01";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 1:
                        formattedMonth = "02";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 2:
                        formattedMonth = "03";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 3:
                        formattedMonth = "04";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 4:
                        formattedMonth = "05";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 5:
                        formattedMonth = "06";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 6:
                        formattedMonth = "07";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 7:
                        formattedMonth = "08";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 8:
                        formattedMonth = "09";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 9:
                        formattedMonth = "10";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 10:
                        formattedMonth = "11";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                        
                        case 11:
                        formattedMonth = "12";
                        //System.out.println(m.values()[mmInt].name());
                        break;
                    }
                    
                    if (year%4==0) //leap year
                    {
                        objectLeapYearFebruaryDays = m.FEB.days; // obtain number days from enum
                        intLeapYearFebruaryDays = (int) (objectLeapYearFebruaryDays)+1; //increase by 1
                        leapYear=true; //flag set to true
                    }
                    //System.out.println("This is the month:" + m.name());
                    
                    days = m.days;
                    
                    if (m.name()=="FEB" && leapYear)
                    {
                        days = (Object) intLeapYearFebruaryDays; // this is officially setting days as 29
                    }
                    daysMonth = (int) days;

                    if (processedFirstMonth)
                    {
                        ddInt=1; //will ensure second month will start from first day DD
                    }
                    
                    //moving through days
                    for (int k=ddInt; k<=(int) daysMonth; k++)
                    {
                        month = m.month; //setting month object to enum variable month.... i.e JAN, FEB
                        temp=""; // clearing value from temp
                        temp = Integer.toString(k);
                        
                        if (k<10)
                        {
                            //temp will store DD if day of month is less than 10
                            temp = prefixZero.toString() + Integer.toString(k);
                        }
                        
                        //System.out.println("This is the day: " + temp);
                        finalDate = temp + "/" + formattedMonth + "/" + year; //full DD/MM/YYYY
                        finalDatePalindrome = temp + formattedMonth + year; //DDMMYYYY
                        //System.out.println("This is final date: " + finalDate);
                        
                        checkPalindrome(finalDate, finalDatePalindrome); // method call
                        //System.out.println(temp);
                        //System.out.println(formattedMonth);

                        if (k==daysMonth && formattedMonth=="12") // if it reached last day month of December
                        {
                            year++; // increase the year
                            mmInt=0; // this starts again new year.. 0 since used in zero index scenarios...
                            newYearRollOver=true; //sets flag new year
                        }
                    }
                    
                    processedFirstMonth=true; // once flag set, no need to set back to false... since all
                    // months across years will start from 1
                    
                    if (!newYearRollOver) // this now deals with all other scenarios of increasing month  //exception December above
                    {
                        mmInt=mmInt+1;
                    }
                } // this terminates the enum of traversing months
                
                monthcount++;
            }while(monthcount<=12);
        } // end for loop (years)
    } // terminates createdate method
} // end of class