public class ConstellationUtil {
private final static String[] constellationArr = new String[] { "摩羯座",
"水瓶座", "雙魚座", "白羊座", "金牛座", "雙子座", "巨蟹座", "獅子座", "處女座", "天秤座",
"天蠍座", "射手座", "摩羯座" };
private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23,
23, 23, 24, 23, 22 };
public static String calculateConstellation(String birthday) { //傳進的值格式爲 1991-10-08
if (birthday == null || birthday.equals("")) {
return "";
}
String[] birthdayElements = birthday.split("-");
int month = Integer.parseInt(birthdayElements[1]);
int day = Integer.parseInt(birthdayElements[2]);
return day < dayArr[month - 1] ? constellationArr[month - 1]
: constellationArr[month];
}