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

Create a class called Month (java file called Month.java) with the (exact) follo

ID: 3824074 • Letter: C

Question

Create a class called Month (java file called Month.java) with the (exact) following fields and methods (these names and caps exactly): 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 [Your Name]-Assignment6 (replace [Your Name] 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:

Explanation / Answer

ANSWER- I write code of this program in java according to the all requirements of the question.

package my_chegg_package;

public class Month

{
private int monthNumber;
String[] monthNames = { "January", "Februry", "March",
                   "April", "May", "June", "July", "August", "September",
                   "October", "November", "December" }; //Months.




public Month()
    {
    monthNumber = 1;
    }

public Month(int monthNumber)
    {
    if((monthNumber < 1 ) || ( monthNumber > 12))
    {
       monthNumber = 1;
       }
    else
    {
       this.monthNumber = monthNumber;}
    }

public Month(String mName)
{
   int index = -1;
        for (int i=0;i<monthNames.length;i++) {
            if (monthNames[i].equals(mName)) {
                index = i;
                break;
            }
        }
        monthNumber = (index+1);
}
public void setMonthNumber(int mNumber)
{
if((mNumber < 1) || (mNumber > 12))
{
monthNumber = 1;
}
monthNumber = mNumber;

}
public int getMonthNumber()
{
return monthNumber;
}

public void setMonthName(String monthName)
    {
    int index = -1;
    for (int i=0;i<monthNames.length;i++) {
        if (monthNames[i].equals(monthName)) {
            index = i;
            break;
        }
    }
    monthNumber = (index+1);
    }
public String getMonthName()
{
   String mName=null;
   for (int i=0;i<monthNames.length;i++) {
       if((i+1)== this.monthNumber)
       {
           mName=monthNames[i];
       }
   }
   return mName;
}
/**
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.
*/

public boolean Equals(Month m1)
    {
    if(monthNumber == m1.getMonthNumber())
    return true;
    else
    return false;
    }


public boolean lessThan(Month m1)
    {
    if(monthNumber > m1.monthNumber)
    return true;
    else
    return false;
    }

public boolean greaterThan(Month m1)
    {
    if(monthNumber < m1.monthNumber)
    return true;
    else
    return false;
    }
}

package my_chegg_package;

public class Project
{
   public static void main (String[] args){
       Month month1 = new Month();
       Month month2 = new Month(2);
       Month month3 = new Month("October");
       System.out.println("month1 Number : " + month1.getMonthNumber()+" "+ "month1 Name   :"+ month1.getMonthName());
       System.out.println("month2 Number : " + month2.getMonthNumber()+" "+ "month2 Name   :"+ month2.getMonthName());
       System.out.println("month3 Number : " + month3.getMonthNumber()+" "+ "month3 Name   :"+ month3.getMonthName());
      
       month1.setMonthNumber(9);
        month2.setMonthName("September");
      
        System.out.println("after setMonthNumber 9 and set Month Name Sepetember month1,month2,month3");
        System.out.println(month1.getMonthName());
        System.out.println(month2.getMonthName());
        System.out.println(month2.getMonthName());
      
        if (month1.equals(month2))
              System.out.println(month1 + ":: and :: " + month2 + " : are equal.");
          else
             System.out.println(month1 + " ::and ::" + month2 + " : are NOT equal.");
      
        if (month2.greaterThan(month3))
             System.out.println(month2 + ":: is greater than :: " + month3);
          else
             System.out.println(month2 + ":: is NOT greater than :: " + month3);
  
     
          if (month3.lessThan(month1))
             System.out.println(month3 + ":: is less than :: " + month1);
          else
             System.out.println(month3 + ":: is NOT less than :: " + month1);
   }
}

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