我得到了一种根据用户输入定义季节的方法。例如:1/6 = Winter 它可以工作,但似乎应该有一种更简单的方法来做到这一点,而不是拥有所有这些代码。有什么建议么?
public String getSeason()
{
String result = "UNKNOWN";
if (month == 1 && day >= 1)
{
result = "WINTER";
}
else if (month == 2 && day >= 1)
{
result = "WINTER";
}
else if (month == 3 && day <= 20)
{
result = "WINTER";
}
else if (month == 3 && day >= 21)
{
result = "SPRING";
}
else if (month == 4 && day >= 1)
{
result = "SPRING";
}
else if (month == 5 && day >= 1)
{
result = "SPRING";
}
else if (month == 6 && day <= 20)
{
result = "SPRING";
}
else if (month == 6 && day >= 21)
{
result = "SUMMER";
}
else if (month == 7 && day >= 1)
{
result = "SUMMER";
}
else if (month == 8 && day >= 1)
{
result = "SUMMER";
}
else if (month == 9 && day <= 22)
{
result = "SUMMER";
}
else if (month == 9 && day >= 23)
{
result = "FALL";
}
else if (month == 10 && day >= 1)
{
result = "FALL";
}
else if (month == 11 && day >= 1)
{
result = "FALL";
}
else if (month == 12 && day <= 20)
{
result = "FALL";
}
else if (month == 12 && day >= 21)
{
result = "FALL";
}
return result;
}