Create a class called Month (java file called Month.java) with the (exact) following fields and methods (these names and caps exactly):
MonthNumber An int field that holds the number of the month (values from 1 to 12)
Month A no-argument constructor that sets the MonthNumber field to 1
Month A constructor that accept the number of the month as an argument ( 1, 2, etc) and sets the MonthNumber field to that value. If a value less than 1 or larger that 12 is passed, the constructor should set MonthNumber to 1
Month A constructor that accept the name of the month as an argument ( January, February , etc) and sets the MonthNumber field to the corresponding number.
GetMonthNumber A method that returns the MonthNumber field value
SetMonthNumber A method that accept an int number as an argument and sets the MonthNumber field to that number
GetMonthName A method that returns the name of the month corresponding to the MonthNumber field value
SetMonthName A method that accept a string value as an argument (representing the name of the month: January, February , etc.) and sets the MonthNumber field to the corresponding number ( 1, 2, etc)
Equals A method that accepts a Month object as an argument and returns true if the data from that object (its MonthNumber ) is the same as the MonthNumber field or false otherwise
GreaterThan A method that accepts a Month object as an argument and returns true if the data from that object (its MonthNumber ) is greater than the MonthNumber field or false otherwise
LessThan A method that accepts a Month object as an argument and returns true if the data from that object (its MonthNumber ) is less than the MonthNumber field or false otherwise
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]Assignment2 (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 Month1, 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 argument September to set the Month2 object value to 9.
Use the GetMonthName to get the month name from objects Month1, Month2, and Month3 and output the values to the console.
Use the Equals method of Month1 to compare its value with Month2 value and output the result to the console.
Use the GreaterThan method of Month2 to compare its value with Month3 value and output the result to the console.
Use the LessThan method of Month3 to compare its value with Month1 value and output the result to the console.
Create a loop from 1 to 12 that use the GetMonthName to determine the corresponding month names (for the numbers 1 to 12) and prints the names out to the console (one line, separated by commas)
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.