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

Java Homework Help. Can someone please fix my code and have my program compile c

ID: 3831221 • Letter: J

Question

Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks for the help.

Specifications:

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. 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”.

Here is my code so far:

public class Month
{

private int Month;
private int MonthNumber;
private String Name;


public setMonthNumber (int)
{
Month = 1;
}
public getMonthNumber(int)
{
return Month;
}

public getMonthName(String m)
{
if (m.equals == 1)
{
Name = "January";
}
else if (m.equals == 2)
{
Name = "Febuary";
}
else if (m.equals == 3)
{
Name = "march";
}
else if (m.equals == 4)
{
Name = "April";
}
else if (m.equals == 5)
{
Name = "may";
}
else if (m.equals == 6)
{
Name = "june";
}
else if (m.equals == 7)
{
Name = "july";
}
else if (m.equals == 8)
{
Name = "August";
}
else if (m.equals == 9)
{
Name = "september";
}
else if (m.equals == 10)
{
Name = "october";
}
else if (m.equals == 11)
{
Name = "novermber";
}
else if (m.equals == 12)
{
Name = "December";
}
  
}
public boolean CorrectMonth()
{
if(Month == 1)
{
return true;
}
else
{
return false;
}
}

System.out.println("The month is: " + getMonthName.toString());   


}

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 .

Month Class (8 points) Write a class named Month monthNumber int Month Month (m int) Month name String) setMonthNumber (m int) void getMonthNumber(): int getMonthName(): String toString String equals(month2 Month) boolean

Explanation / Answer

// Month.java

public class Month

{

private int monthNumber;

  

public Month()

{

monthNumber = 1;

}

  

public Month( int num )

{

setMonthNumber(num);

}

  

public Month( String name )

{

if (name.equals("February"))

monthNumber = 2;

else if (name.equals("March"))

monthNumber = 3;

else if (name.equals("April"))

monthNumber = 4;

else if (name.equals("May"))

monthNumber = 5;

else if (name.equals("June"))

monthNumber = 6;

else if (name.equals("July"))

monthNumber = 7;

else if (name.equals("August"))

monthNumber = 8;

else if (name.equals("September"))

monthNumber = 9;

else if (name.equals("October"))

monthNumber = 10;

else if (name.equals("November"))

monthNumber = 11;

else if (name.equals("December"))

monthNumber = 12;

else

monthNumber = 1;

}

  

public void setMonthNumber(int num)

{

if (num < 1 || num > 12)

num = 1;

monthNumber = num;

}

  

public int getMonthNumber()

{

return monthNumber;

}

  

public String getMonthName()

{

switch (monthNumber)

{

case 1:

return "January";

case 2:

return "February";

case 3:

return "March";

case 4:

return "April";

case 5:

return "May";

case 6:

return "June";

case 7:

return "July";

case 8:

return "August";

case 9:

return "September";

case 10:

return "October";

case 11:

return "November";

case 12:

return "December";

}

return "";

}

  

public String toString()

{

return getMonthName();

}

  

public boolean equals(Month m)

{

return monthNumber == m.monthNumber;

}

public boolean greaterThan(Month m)

{

return monthNumber > m.monthNumber;

}

public boolean lessThan(Month m)

{

return monthNumber < m.monthNumber;

}

}

//LandTract.java

public class LandTract

{

private double length;

private double width;

  

public LandTract()

{

length = 0;

width = 0;

}

  

public LandTract(double len, double wid)

{

setLength(len);

setWidth(wid);

}

  

public double area()

{

return length * width;

}

  

public String toString()

{

return "Length: " + length + " Width: " + width;

}

public boolean equals(LandTract l)

{

return area() == l.area();

}

public double getLength()

{

return length;

}

public void setLength(double len)

{

if (len < 0)

len = 0;

this.length = len;

}

public double getWidth()

{

return width;

}

public void setWidth(double wid)

{

if (wid < 0)

wid = 0;

this.width = wid;

}

  

}

//TestLandTract.java

import java.util.Scanner;

public class TestLandTract

{

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

System.out.print("Enter length for land tract 1: ");

double length = scan.nextDouble();

System.out.print("Enter width for land tract 1: ");

double width = scan.nextDouble();

LandTract land1 = new LandTract(length, width);

  

System.out.print("Enter length for land tract 2: ");

length = scan.nextDouble();

System.out.print("Enter width for land tract 2: ");

width = scan.nextDouble();

LandTract land2 = new LandTract(length, width);

  

System.out.println("Area of land1: " + land1.area());

System.out.println("Area of land2: " + land2.area());

if (land1.equals(land2))

System.out.println("They are of equal size.");

else

System.out.println("They are NOT of equal size.");

}

}

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