Java开发技术@IT·互联网

-CoderOilStation TCS needs 20

2025-06-13  本文已影响0人  程序员编程助手

-CoderOilStation

TCS needs 2025/06/14

dayOfProgrammer

* American time machine test on the Russia Calendar

* return 256th day of programmer day

* exists two type calendar

* Julian Calendar

* Gregorian Calendar

* output

* that day by using simple date format dd.mm.yyy

* constriants:

* 1700<=year<=2700

* 1918 year is a special year

* the 32th day January is February 14th this year and this month is beging with14th day

* from 1700 to 1917 using Julian Calendar

* from 1919 to 2700 using Gregorian Calendar

/**

     * dayOfProgrammer

     * American time machine test on  the Russia Calendar

     * return 256th day of programmer  day

     * exists two type calendar

     * Julian Calendar

     * Gregorian Calendar

     * output

     * that day by using simple date  format dd.mm.yyy

     * constriants:

     * 1700<=year<=2700

     * 1918 year is a special year

     * the 32th day January is February  14th this year and this month is beging with 14th day

     * from 1700 to 1917 using Julian  Calendar

     * from 1919 to 2700 using  Gregorian Calendar

     *

     * @param year

     * @return

     */

    public  static String dayOfProgrammer(int year) {

        if (year < 1700 || year >  2700) {

            return null;

        }

//        if ()

return null;

    }

    /**

     * get day of programmer by using  Russia Gregorian Calendar

     * 256th day of programmer in this  input year

     * @param year

     * @return

     */

public static String dayOfProgrammerGregorian(int  year) {

        if (!checkIsGregorianYear(year))  {

            return null;

        }

        StringBuilder stringBuilder = new  StringBuilder();

        stringBuilder.append(year);

        if (checkIsLeapYear(year))  {

            // Jan31 Feb29 March31  April30 May31 June30 July31 August31 Sept30 Octor31 Norve30 Decem31

int yearWhichMonth = CalendarConstant.WHICHDAYOFPROGRAMMER

  / 29;

            if(yearWhichMonth==GregorianCalendarMonthEnum.JAN.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            }else if(yearWhichMonth==GregorianCalendarMonthEnum.FEB.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            }else if(yearWhichMonth==GregorianCalendarMonthEnum.MAR.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            }else if(yearWhichMonth==GregorianCalendarMonthEnum.APR.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            }else if(yearWhichMonth==GregorianCalendarMonthEnum.MAY.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            }else if(yearWhichMonth==GregorianCalendarMonthEnum.JUN.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            }else if(yearWhichMonth==GregorianCalendarMonthEnum.JUL.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            } else if(yearWhichMonth==GregorianCalendarMonthEnum.AUG.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            }else if(yearWhichMonth==GregorianCalendarMonthEnum.SEP.getMonthVal()){

                stringBuilder.append(GregorianCalendarMonthEnum.JAN.getKey());

            } else if (yearWhichMonth==GregorianCalendarMonthEnum.OCT.getMonthVal())  {

            } else if (yearWhichMonth==GregorianCalendarMonthEnum.NOV.getMonthVal())  {

            } else if (yearWhichMonth==GregorianCalendarMonthEnum.DEC.getMonthVal())  {

            }

        }

        return null;

    }

    /**

     * check year if is leap year

     *

     * @param year

     * @return

     */

public static Boolean checkIsLeapYear(int  year) {

        if (year < 1700 || year >  2700) {

            return null;

        }

        if (year % 400 == 0 || (year % 4  == 0 && year % 100 != 0)) {

            return true;

        }

        return false;

    }

    /**

     * check year if it is Russia  Julian Calendar

     *

     * @param year

     * @return

     */

public static Boolean checkIsJulianYear(int  year) {

        if (year < 1700 || year >  2700) {

            return null;

        }

        if (year >= 1700 && year  <= 1917) {

            return true;

        }

        return false;

    }

    /**

     * check year if it is Russia Greborian  Calendar

     *

     * @param year

     * @return

     */

public static Boolean checkIsGregorianYear(int  year) {

        if (year < 1700 || year >  2700) {

            return null;

        }

        if (year > 1918 && year  <= 2700) {

            return true;

        }

        return false;

    }

    /**

     * check year if it is Russia  special transmition year

     *

     * @param year

     * @return

     */

public static Boolean checkIsRussiaSpecialTransitionYear(int  year) {

        if (year < 1700 || year >  2700) {

            return null;

        }

        if (year == 1918) {

            return true;

        }

        return false;

    }

package tcs.com.utils.constant;

public class CalendarConstant {

    public static final intGREGORIANLEAPYEARTOTALDAYS=366;

    public static final intGREGORIANNOTLEAPYEARTOTALDAYS=365;

    public static final intWHICHDAYOFPROGRAMMER=256;

}

package tcs.com.utils.enumration;

public enum GregorianCalendarMonthEnum {

    JAN("JAN","1

月",1),

    FEB("FEB","2

月",2),

    MAR("MAR","3

月",3),

    APR("APR","4

月",4),

    MAY("MAY","5

月",5),

    JUN("JUN","6

月",6),

    JUL("JUL","7

月",7),

    AUG("AUG","8

月",8),

    SEP("SEP","9

月",9),

    OCT("OCT","10

月",10),

    NOV("NOV","11

月",11),

    DEC("DEC","12

月",12)

    ;

    private String key;

    private String value;

    private Integer monthVal;

    private GregorianCalendarMonthEnum(String  key, String value, Integer monthVal) {

        this.key = key;

        this.value = value;

        this.monthVal = monthVal;

    }

    public String getKey(){

        return this.key;

    }

    public String getValue(){

        return this.value;

    }

    public Integer getMonthVal(){

        return this.monthVal;

    }

}

上一篇 下一篇

猜你喜欢

热点阅读