Answer:
See explaination
Step-by-step explanation:
public class YearToAnimal {
static void yearToAnimalZodiac(int year){
String[] animals = {"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"};
int baseYear = 2020;
int index = (year - baseYear) % 12;
// in case of negative index, change it to positive
if(index < 0)
index = 12 + index;
System.out.println(year + ": " + animals[index]);
}
// some test cases
public static void main(String[] args) {
yearToAnimalZodiac(2020);
yearToAnimalZodiac(2021);
yearToAnimalZodiac(2019);
yearToAnimalZodiac(2009);
yearToAnimalZodiac(2008);
yearToAnimalZodiac(2007);
}
}