I have done most of the code but am struggling a bit now, please help
The brief is
Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example, January would be 1, February would be 2, and so forth. The class should also have a static field named lastMonthCreated that holds the number of the month which was last constructed. In addition, provide the following methods:
•A no-arg constructor that sets the monthNumber field to 1.
•A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than 1 or greater than 12 is passed, the constructor should set monthNumber to 1.
•A constructor that accepts the name of the month, such as "January" or "February" as an argument. It should set the monthNumber field to the correct corresponding value.
•A setMonthNumber method that accepts an int argument, which is assigned to the monthNumber field. If a value less than 1 or greater than 12 is passed, the method should set monthNumber to 1.
•A getMonthNumber method that returns the value in the monthNumber field.
•A getMonthName method that returns the name of the month. For example, if the monthNumber field contains 1, then this method should return "January".
•A getLastMonthCreated method that returns the value in the lastMonthCreated field.
•A toString method that returns the same value as the getMonthName method.
•An equals method that accepts a Month object as an argument. If the argument object holds the same data as the calling object, this method should return true. Otherwise, it should return false.
•A greaterThan method that accepts a Month object as an argument. If the calling object's monthNumber field is greater than the argument's monthNumber field, this method should return true. Otherwise, it should return false.
•A lessThan method that accepts a Month object as an argument. If the calling object's monthNumber field is less than the argument's monthNumber field, this method should return true. Otherwise, it should return false.
The help I would like is with the following error message
Month.java:81: cannot find symbol
symbol : variable monthNumb
location: class Month
if (month2.getMonthNumber() == monthNumb)
And also how to put in the getLastMonthCreated in
My code is
public class Month
{
private int monthNumber;
public Month(int m)
{
if (m < 1 || m > 12)
monthNumber = 1;
else
monthNumber = m;
}
public Month(String name)
{
if (name.equalsIgnoreCase("january")) monthNumber = 1;
else if (name.equalsIgnoreCase("february")) monthNumber = 2;
else if (name.equalsIgnoreCase("march")) monthNumber = 3;
else if (name.equalsIgnoreCase("april")) monthNumber = 4;
else if (name.equalsIgnoreCase("may")) monthNumber = 5;
else if (name.equalsIgnoreCase("june")) monthNumber = 6;
else if (name.equalsIgnoreCase("july")) monthNumber = 7;
else if (name.equalsIgnoreCase("august")) monthNumber = 8;
else if (name.equalsIgnoreCase("september"))monthNumber = 9;
else if (name.equalsIgnoreCase("october")) monthNumber = 10;
else if (name.equalsIgnoreCase("november")) monthNumber = 11;
else if (name.equalsIgnoreCase("december")) monthNumber = 12;
else monthNumber = 1;
}
public void setMonthNumber(int m)
{
if (m < 1 || m > 12)
System.out.println("Invalid Month Number");
else monthNumber = m;
}
public int getMonthNumber()
{
return monthNumber;
}
public String getMonthName()
{
String name;
switch (monthNumber)
{
case 1: name = "January";
break;
case 2: name = "February";
break;
case 3: name = "March";
break;
case 4: name = "April";
break;
case 5: name = "May";
break;
case 6: name = "June";
break;
case 7: name = "July";
break;
case 8: name = "August";
break;
case 9: name = "September";
break;
case 10: name = "October";
break;
case 11: name = "November";
break;
case 12: name = "December";
break;
default: name = "Unknown";
}
return name;
}
public String toString()
{
return getMonthName();
}
public boolean equals(Month month2)
{
boolean status;
if (month2.getMonthNumber() == monthNumb)
status = true;
else
status = false;
return status;
}
public boolean greaterThan(Month month2)
{
boolean status;
if (monthNumber > month2.getMonthNumber())
status = true;
else
status = false;
return status;
}
public boolean lessThan(Month month2)
{
boolean status;
if (monthNumber < month2.getMonthNumber())
status = true;
else
status = false;
return status;
}
}