Java judges birthday and Constellation Based on birthday

Source: Internet
Author: User

Package com. test;

Import java. util. calendar;

Public class test {

/**
* @ Param ARGs
*/
 
Public static final string [] zodiacarr = {"monkey", "chicken", "dog", "Swine", "rat", "Ox", "Tiger ", "rabbit", "dragon", "snake", "horse", "goat "};

Public static final string [] constellationarr = {"Aquarius", "Pisces", "Aries", "Taurus", "Gemini", "cancer", "Leo ", "Virgo", "Libra ",
"Scorpio", "Sagittarius", "Capricorn "};

Public static final int [] constellationedgeday = {20, 19, 21, 21, 21, 22, 23, 23, 23, 22, 22 };

/**
* Obtain the Chinese zodiac by date
* @ Return
*/
Public static string date2zodica (calendar time ){
Return zodiacarr [time. Get (calendar. Year) % 12];
}

/**
* Retrieve the Constellation by date
* @ Param time
* @ Return
*/
Public static string date2constellation (calendar time ){
Int month = time. Get (calendar. month );
Int day = time. Get (calendar. day_of_month );
If (day <constellationedgeday [month]) {
Month = month-1;
}
If (month> = 0 ){
Return constellationarr [month];
}
// Default to return magic wand
Return constellationarr [11];
}
 
Public static void main (string [] ARGs ){
String test = date2constellation (calendar. getinstance ());
System. Out. println ("constellation:" + test );
String test1 = date2zodica (calendar. getinstance ());
System. Out. println ("Zodiac:" + test1 );
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.