Avatar of tribalzoid
 asked on

java program for chinese horoscope...

The platform used is linux system...The program will reads in user input on birth year and prints out the corresponding
Chinese horoscope sign. The program allows a user to enquire about horoscope signs until a
sentinel value of ? is used to terminate the process. There are 12 signs in the Chinese
horoscope. The calculation of a horoscope sign is based on birth year. The 12 Chinese horoscope
signs and some of their corresponding years are given below:
Horoscope Sign Birth Year
Rat 1972, 1984, 1996?
Cow 1973, 1985, 1997?
Tiger 1974, 1986, 1998?
Rabbit 1975, 1987, 1999?
Dragon 1976, 1988, 2000?
Snake 1977, 1989, 2001?
Horse 1978, 1990, 2002?
Goat 1979, 1991, 2003?
Monkey 1980, 1992, 2004?
Rooster 1981, 1993, 2005?
Dog 1982, 1994, 2006?
Pig 1983, 1995, 2007?

I want the output to be as follow...
Enter your birth year: 2006
Your horoscope sign: Dog
Enter your birth year: ?
<Program terminates>

The year of the input does not only applies to the date shown above only... for example if the input for birth year is 1876, it shld display rat horoscope ...
Any body got any idea how to do it...

Avatar of undefined
Last Comment

8/22/2022 - Mon

You can do this:

String[] values = {"Monkey", "Rooster", "Dog", "Pig", "Rat", "Cow", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat"};
int yearOfBirth = 2006 // or any other value;
String value = values[yearOfBirth % 12];

How to do the for loop and if loop in the above logic u gave...

For the above codes, how can it detect monkey is of the certain birthyear...

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.