Java code calculates zodiac signs and constellations by date of birth.
public class Year {
private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23,
23, 23, 24, 23, 22 };
private final static String[] constellationArr = new String[] { "Capricorn",
"Aquarius", "Pisces", "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra",
"Scorpio", "Saturist", "Capricorn" };
/**
* Calculate zodiac signs and constellations based on date of birth
*
* @param args
*/
public static void main(String[] args) {
int month = 7;
int day = 28;
("The constellation is:" + getConstellation(month, day));
("Zodiac sign is:" + getYear(1994));
}
/**
* Java calculates zodiac signs through birthday
*
* @param month
* @param day
* @return
*/
public static String getConstellation(int month, int day) {
return day < dayArr[month - 1] ? constellationArr[month - 1]
: constellationArr[month];
}
/**
* Calculate the zodiac by birthday
*
* @param year
* @return
*/
public static String getYear(int year) {
if (year < 1900) {
return "Unknown";
}
int start = 1900;
String[] years = new String[] { "rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep",
"Monkey", "Chicken", "Dog", "Pig" };
return years[(year - start) % ];
}
}