日期匹配星座,月日匹配星座,android 星座

通过 月日实现匹配星座功能 先准备数据 


Android 版本数据 

我是用的 array  这个可以直接拷贝到项目中直接用

白羊座
金牛座
双子座
巨蟹座
狮子座
处女座
天秤座
天蝎座
射手座
摩羯座
水瓶座
双鱼座


    @string/constellation_aries
    @string/constellation_taurus
    @string/constellation_gemini
    @string/constellation_cancer
    @string/constellation_leo
    @string/constellation_virgo
    @string/constellation_libra
    @string/constellation_scorpio
    @string/constellation_sagittarius
    @string/constellation_capricorn
    @string/constellation_aquarius
    @string/constellation_pisces


String constellation = DateTimeUtil.getConstellation(getResources().getStringArray(R.array.user_constellation),month,day);



java版本数据
public static final String[] contellationArr = {"水瓶座","双鱼座","白羊座","金牛座","双子座","巨蟹座","狮子座","处女座","天秤座","天蝎座","射手座","魔羯座"};


//contellationArr 星座的数组
//month 月份
//day  日

public static String  getConstellation(String [] contellationArr,int month,int day){
    int point = -1;
    Double date = Double.parseDouble(month + "." + day);
    if (3.21 <= date && 4.19 >= date) {
        point = 0;
    } else if (4.20 <= date && 5.20 >= date) {
        point = 1;
    } else if (5.21 <= date && 6.21 >= date) {
        point = 2;
    } else if (6.22 <= date && 7.22 >= date) {
        point = 3;
    } else if (7.23 <= date && 8.22 >= date) {
        point = 4;
    } else if (8.23 <= date && 9.22 >= date) {
        point = 5;
    } else if (9.23 <= date && 10.23 >= date) {
        point = 6;
    } else if (10.24 <= date && 11.22 >= date) {
        point = 7;
    } else if (11.23 <= date && 12.21 >= date) {
        point = 8;
    } else if (12.22 <= date && 12.31 >= date) {
        point = 9;
    } else if (1.01 <= date && 1.19 >= date) {
        point = 9;
    } else if (1.20 <= date && 2.18 >= date) {
        point = 10;
    } else if (2.19 <= date && 3.20 >= date) {
        point = 11;
    }
    if(point == -1) {
        return contellationArr[2];
    }
    return contellationArr[point];
}


 
  

附 :星座月份对照图一张

日期匹配星座,月日匹配星座,android 星座_第1张图片


欢迎大家加入 android开发经验交流群:454430053



你可能感兴趣的:(【Android开发基础】)