我为输出月份和月份编号而构建的类构建并运行良好,但是在我的类中的某个地方,我的monthString 只是被分配了空值。我看不到我在哪里遇到了这个错误,我为我的错误代码道歉。泰!~~~
public class MonthClass
{
private int monthNum;
private String monthString;
public MonthClass(int num)
{
monthNum = num;
monthString = monthName(num);
}
public void setmonthNum(int num)
{
monthNum = num;
monthString = monthName(num);
}
public String getmonthName(int num)
{
switch (num)
{
case 1: monthString = "January";
break;
case 2: monthString = "Febuary";
break;
case 3: monthString = "March";
break;
case 4: monthString = "April";
break;
case 5: monthString = "May";
break;
case 6: monthString = "June";
break;
case 7: monthString = "July";
break;
case 8: monthString= "Augest";
break;
case 9: monthString = "September";
break;
case 10: monthString = "October";
break;
case 11: monthString = "November";
break;
case 12: monthString = "December";
break;
default: monthString = "This is not a month, re-enter a number";
break;
}
return monthString;
}
public String monthName(int num)
{
return monthString;
}
public String toString()
{
return "The month number is " + monthNum + " and the month name is " + monthString;
}
}