java根据日期判断星座_给定公历日期计算12星座(Java代码实现)

给定公历日期,计算返回该日期对应的十二星座。

public static String getXingZuoName(int month, int day);

注意:参数month和day均为公历月、日。

返回的中文星座名如:处女座。

import java.util.Map;

import java.util.HashMap;

import java.util.ArrayList;

import java.util.List;

//importandroid.util.Log;

public class XingZuo {

private static List> LIST = null;

private static float[][] floatXingZuo = null;

public XingZuo() {

// LIST=loadXingZuo12();

// floatXingZuo=loadXingZuoFloatValue();

}

public static String getXingZuoName(int month, int day) {

if (floatXingZuo == null)

floatXingZuo = loadXingZuoFloatValue();

String ds = String.format("%02d", day);

float target = Float.valueOf(month + "." + ds);

boolean bool1 = Float.compare(target, 12.22f) >= 0 ? true : false;

boolean bool2 = Float.compare(target, 1.20f) <= 0 ? true : false;

if (bool1 || bool2) {

return "摩羯座";

}

int i;

boolean b1, b2;

for (i = 0; i < 12; i++) {

b1 = Float.compare(target, floatXingZuo[0][i]) >= 0 ? true : false;

b2 = Float.compare(target, floatXingZuo[1][i]) <= 0 ? true : false;

if (b1 && b2)

break;

}

Map map = (Map) (LIST.get(i));

return map.get("XINGZUO_NAME") + "";

}

private static float[][] loadXingZuoFloatValue() {

if (LIST == null)

LIST = loadXingZuo12();

Map map = null;

// String xzname=null;

int mind, maxd, minm, maxm;

float[][] fxingzuo = new float[2][12];

float start, end;

for (int i = 0; i < 12; i++) {

map = (Map) (LIST.get(i));

mind = Integer.parseInt(map.get("MIN_DAY") + "");

maxd = Integer.parseInt(map.get("MAX_DAY") + "");

minm = Integer.parseInt(map.get("MIN_MONTH") + "");

maxm = Integer.parseInt(map.get("MAX_MONTH") + "");

start = Float.valueOf(minm + "." + mind);

end = Float.valueOf(maxm + "." + maxd);

fxingzuo[0][i] = start;

fxingzuo[1][i] = end;

}

return fxingzuo;

}

private static List loadXingZuo12() {

String XINGZUO_NAME = "XINGZUO_NAME";

String MIN_DAY = "MIN_DAY";

String MIN_MONTH = "MIN_MONTH";

String MAX_DAY = "MAX_DAY";

String MAX_MONTH = "MAX_MONTH";

List> list = new ArrayList>();

Map map = null;

map = new HashMap();

map.put(XINGZUO_NAME, "白羊座");

map.put(MIN_DAY, 21);

map.put(MAX_DAY, 20);

map.put(MIN_MONTH, 3);

map.put(MAX_MONTH, 4);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "金牛座");

map.put(MIN_DAY, 21);

map.put(MAX_DAY, 21);

map.put(MIN_MONTH, 4);

map.put(MAX_MONTH, 5);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "双子座");

map.put(MIN_DAY, 22);

map.put(MAX_DAY, 21);

map.put(MIN_MONTH, 5);

map.put(MAX_MONTH, 6);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "巨蟹座");

map.put(MIN_DAY, 22);

map.put(MAX_DAY, 22);

map.put(MIN_MONTH, 6);

map.put(MAX_MONTH, 7);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "狮子座");

map.put(MIN_DAY, 23);

map.put(MAX_DAY, 23);

map.put(MIN_MONTH, 7);

map.put(MAX_MONTH, 8);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "处女座");

map.put(MIN_DAY, 24);

map.put(MAX_DAY, 23);

map.put(MIN_MONTH, 8);

map.put(MAX_MONTH, 9);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "天秤座");

map.put(MIN_DAY, 24);

map.put(MAX_DAY, 23);

map.put(MIN_MONTH, 9);

map.put(MAX_MONTH, 10);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "天蝎座");

map.put(MIN_DAY, 24);

map.put(MAX_DAY, 22);

map.put(MIN_MONTH, 10);

map.put(MAX_MONTH, 11);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "射手座");

map.put(MIN_DAY, 23);

map.put(MAX_DAY, 21);

map.put(MIN_MONTH, 11);

map.put(MAX_MONTH, 12);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "摩羯座");

map.put(MIN_DAY, 22);

map.put(MAX_DAY, 20);

map.put(MIN_MONTH, 12);

map.put(MAX_MONTH, 1);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "水瓶座");

map.put(MIN_DAY, 21);

map.put(MAX_DAY, 19);

map.put(MIN_MONTH, 1);

map.put(MAX_MONTH, 2);

list.add(map);

map = new HashMap();

map.put(XINGZUO_NAME, "双鱼座");

map.put(MIN_DAY, 20);

map.put(MAX_DAY, 20);

map.put(MIN_MONTH, 2);

map.put(MAX_MONTH, 3);

list.add(map);

return list;

}

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值