Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are going to lose points if you do not name the class, the fields, or method

ID: 3866921 • Letter: Y

Question

You are going to lose points if you do not name the class, the fields, or methods as requested. You should not have a field for the month name: your code should compute the name of the month from the number when needed Create a program/project called [YourName]-Assignment6 (replace [YourName] with your actual name) in the same project as the Month.java. You will need to add the class Month to the project and add your code to the project class main method. The program (code) should Create three objects: Month1 one using the first constructor (with no arguments) and Month2 using the second constructor with 2 as an argument, and Month3 using the third constructor with "October" as an argument Use the GetMonthNumber to get the month number from objects Month1. Month2, and Month3 and output the values to the console Use the GetMonthName to get the month name from objects Monthl, Month2, and Month3 and output the values to the console Use the SetMonthNumber to set the Month1 object value to 9 Use the SetMonthName with Use the GetMonthName to get the month name from objects Monthl, Month2, and Month3 and output the values to the console Use the Equals method of Month1 to Use the GreaterThan method of Month2 to com Use the LessThan method of Month3 to c t September" to set the Month2 object value to 9 e its value with Month2 value and output the result to the console its value with Month3 value and output the result to the console re its value with Month1 value and output the result to the console

Explanation / Answer

File Month.java:

public class Month {
int MonthNumber;
public Month()
{
MonthNumber = 1;
}
public Month(int no)
{
if(no >= 1 && no <= 12) // If MonthNumber is within range
MonthNumber = no;
else
MonthNumber = 1;
}
public Month(String MonthName)
{
int i;
MonthNumber = 1;
String Months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
for(i = 0; i < 12; i++)
{
if(Months[i].equalsIgnoreCase(MonthName)) // If name of month matches
{
MonthNumber += i;
break;
}
}
}
public int GetMonthNumber()
{
return MonthNumber;
}
public String GetMonthName()
{
String Months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
return Months[MonthNumber + 1];
}
public void SetMonthNumber(int no)
{
MonthNumber = no;
}
public void SetMonthName(String MonthName)
{
// Works in a similar way like the constructor
int i;
String Months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
for(i = 0; i < 12; i++)
{
if(Months[i].equalsIgnoreCase(MonthName))
{
MonthNumber = i + 1;
break;
}
}
}
public boolean Equals(Month object)
{
if(MonthNumber == object.GetMonthNumber()) // Checking for equality
return true;
else
return false;
}
public boolean GreaterThan(Month object)
{
if(MonthNumber < object.GetMonthNumber()) // Checking for condition
return true;
else
return false;
}
public boolean LessThan(Month object)
{
if(MonthNumber > object.GetMonthNumber()) // checking for condition
return true;
else
return false;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote