Ad
import java.util.*;
public class Main {

    public static void main(String[] args) {
        int finalResult, month, date, year, flag = 0;
        String alphabeticalRepresentationOfMonth, suffix;
        System.out.println("Lets play a game");
        System.out.println("I'll guess your Birthday!");
        System.out.println("You just have to calculate stuffs");
        System.out.println("Note: You may need a calculator ");
        System.out.println("Okay, let's start");
        System.out.println("Follow every step carefully");
        System.out.println("Note: If you are using a calculator, press 'equal to' ('=') button after every step ");
        System.out.println("Step 1: Multiply your birth month by 5 ");
        System.out.println("Step 2: Add 6 to the result");
        System.out.println("Step 3: Multiply the result by 4");
        System.out.println("Step 4: Add 9 to the result");
        System.out.println("Step 5: Multiply the result by 5");
        System.out.println("Step 6: Add your birth date to the result");
        System.out.println("Now, enter the final result");
        Scanner sc = new Scanner(System.in);
        finalResult = sc.nextInt();
        finalResult -= 165;
        month = finalResult / 100;
        date = finalResult % 100;
        if (month == 1 || month == 3 || month == 5 || month == 7 || month ==8 || month == 10 || month == 12)
            if(date > 31) {
                System.out.println("Invalid Input");
                System.exit(0);
            }
        if(month == 4 || month == 6 || month == 9 || month == 11)
            if(date > 30){
                System.out.println("Invalid Input");
                System.exit(0);
            }


        switch(month){
            case 1:
                alphabeticalRepresentationOfMonth = "January";
                break;
            case 2: alphabeticalRepresentationOfMonth = "February";
                break;
            case 3: alphabeticalRepresentationOfMonth = "March";
                break;
            case 4: alphabeticalRepresentationOfMonth = "April";
                break;
            case 5: alphabeticalRepresentationOfMonth = "May";
                break;
            case 6: alphabeticalRepresentationOfMonth = "June";
                break;
            case 7: alphabeticalRepresentationOfMonth = "July";
                break;
            case 8: alphabeticalRepresentationOfMonth = "August";
                break;
            case 9: alphabeticalRepresentationOfMonth = "September";
                break;
            case 10: alphabeticalRepresentationOfMonth = "October";
                break;
            case 11: alphabeticalRepresentationOfMonth = "November";
                break;
            case 12: alphabeticalRepresentationOfMonth = "December";
                break;
            default:
                alphabeticalRepresentationOfMonth = "NULL";
                System.out.println("Invalid Input");
                System.exit(0);

        }
        if(date >= 10 && date <= 20 )
            suffix = "th";
        else {
            switch (date % 10) {
                case 1:
                    suffix = "st";
                    break;
                case 2:
                    suffix = "nd";
                    break;
                case 3:
                    suffix = "rd";
                    break;
                default:
                    suffix = "th";
                    break;
            }
        }
        System.out.println("Enter your age: ");
        year = 2019 - sc.nextInt();
        if(year % 4 == 0){
            if(year % 100 == 0){
                if(year % 400 == 0)
                    flag = 1;
                else
                    flag = 0;
            }
            else
                flag = 1;
        }
        else
            flag = 0;
        if(flag == 1 && month == 2)
            if (date > 29) {
                System.out.println("Invalid Input");
                System.exit(0);
            }
        if(flag == 0 && month == 2)
            if(date > 28){
                System.out.println("Inalid Input");
                System.exit(0);
            }
        System.out.println("Your birthday is on " + date + suffix + " "+ alphabeticalRepresentationOfMonth + ", " + year);

    }
}