The Chinese Zodiac is represented by 12 animals: monkey, rooster, dog, pig, rat,
ID: 3680862 • Letter: T
Question
The Chinese Zodiac is represented by 12 animals: monkey, rooster, dog, pig, rat, ox, tiger, rabbit, dragon, snake horse goat, on a twelve-year cycle.
Draw a flowchart and write a program in java that keeps inputting years; a negative number terminates the program. The program then prints the Chinese Zodiac sign for a given year.
You must use the following three methods for this program:
1) A method that returns a String array with 12 animal names.
Input to the method: none
Output of the method: a String array of Chinese Zodica
2) A method that returns the user entered number (the year)
Input to the method: none
Output of the method: an integer of the year
3) A method that prints the Chinese Zodica sign for a given year
Input to the method: an integer of the year
Output of the method: none (void method)
Explanation / Answer
class ChineseZodiacSign{
String zodiac[]={"monkey", "rooster", "dog", "pig", "rat", "ox", "tiger","rabbit", "dragon", "snake" ,"horse", "goat"};
int year[];
public string signs(){
return zodiac;
}
public int year(){
return year;
}
public void zodiacSign(int year){
if(year==2005||year==1993||year=1981||year==1969||year==1957)
System.out.println("rooster")
elseif(year==2006||year==1994||year=1982||year==1970||year==1958)
System.out.println("dog")
elseif(year==2007||year==1995||year=1983||year==1971||year==1959)
System.out.println("pig")
elseif(year==2008||year==1996||year=1984||year==1972||year==1960)
System.out.println("rat")
elseif(year==2009||year==1997|year=1985||year==1973||year==1961)
System.out.println("ox")
elseif(year==2010||year==1998||year=1986||year==1974||year==1962)
System.out.println("tiger")
elseif(year==2011||year==1999||year=1987||year==1975||year==1963)
System.out.println("rabbit")
elseif(year==2012||year==2000||year=1988||year==1976||year==1964)
System.out.println("dragon")
elseif(year==2013||year==2001||year=1989||year==1977||year==1965)
System.out.println("snake")
elseif(year==2014||year==2002||year=1990||year==1978||year==1966)
System.out.println("horse")
elseif(year==2015||year==2003||year=1991||year==1979||year==1967)
System.out.println("goat")
elseif(year==2016||year==2004||year=1992||year==1980||year==1968)
System.out.println("monkey")
}
public static void main(String... s){
Scanner sc=new Scanner(System.in);
System.out.println("Enter your year");
int year=sc.nextInt();
if (year<0){
System.out.println("invalid year");
}
ChineseZodiacSign c=new ChineseZodiacSign(year);
c.zodiacSign();
}
}