Why this program is not running? * * */ public class Month { // declare field(s)
ID: 3718321 • Letter: W
Question
Why this program is not running?
*
*
*/
public class Month
{
// declare field(s)
int monthNumber;
public Month()
{
this.monthNumber=1;
// implement this constructor
}
public Month(int m)
{
if(m<1||m>12)
this.monthNumber=1;
else
this.monthNumber=m;
// implement this constructor
}
public Month(String name)
{
if(name.equals("January"))
this.monthNumber=1;
else if(name.equals("February"))
this.monthNumber=2;
else if(name.equals("March"))
this.monthNumber=3;
else if(name.equals("April"))
this.monthNumber=4;
else if(name.equals("May"))
this.monthNumber=5;
else if(name.equals("June"))
this.monthNumber=6;
else if(name.equals("July"))
this.monthNumber=7;
else if(name.equals("August"))
this.monthNumber=8;
else if(name.equals("September"))
this.monthNumber=9;
else if(name.equals("October"))
this.monthNumber=10;
else if(name.equals("November"))
this.monthNumber=11;
else if(name.equals("December"))
this.monthNumber=12;
// implement this constructor
}
public void setMonthNumber(int m)
{
this.monthNumber=m;// implement this method
}
public int getMonthNumber()
{
// implement this method
return this.monthNumber;
}
public String getMonthName()
{
String temp;
switch(this.monthNumber){
case 1:
temp="January";
break;
case 2:
temp="February";
break;
case 3:
temp="March";
break;
case 4:
temp="April";
break;
case 5:
temp="May";
break;
case 6:
temp="June";
break;
case 7:
temp="July";
break;
case 8:
temp="August";
break;
case 9:
temp="September";
break;
case 10:
temp="October";
break;
case 11:
temp="November";
break;
case 12:
temp="December";
break;
default:
temp="January";
}
// implement this method
return temp;
}
public String toString()
{
// implement this method
return this.getMonthName();
}
public boolean equals(Month otherMonth)
{
if(this.monthNumber==otherMonth.monthNumber)
return true;
else
// implement this method
return false;
}
public boolean greaterThan(Month otherMonth)
{
if(this.monthNumber>otherMonth.monthNumber)
return true;
else
// implement this method
return false;
}
public boolean lessThan(Month otherMonth)
{
if(this.monthNumber<otherMonth.monthNumber)
return true;
else
// implement this method
return false;
}
}
Explanation / Answer
Hi, I have added main method , so it will run now.
Output:
Enter month number (1 <= month <= 12):
5
May
Process finished with exit code 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.