ユーザーからの入力に基づいて季節を定義するメソッドを取得しました。例: 1/6 = 冬 それは動作しますが、このコードをすべて使用する代わりに、これを行うためのより簡単な方法があるはずです。助言がありますか?
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;
}