A 1 point Write a minimal definition for a class named Month
A. (1 point) Write a minimal definition for a class named MonthDay, about which you know nothing else (that is, don’t use the information in the following questions in this answer). Your answer to this question should be just the minimal definition.
B. (2 points) Add a constructor for MonthDay that takes a month and day (of the appropriate primitive type), and stores these values in appropriately-named instance variables.
If the month or day is obviously invalid, then your constructor should throw an IllegalArgumentException. Do not exhaustively check correctness. Instead, limit your checks to checking for a non-negative day and a month between 1 and 12.
Your answer should be the entire class definition.
Solution
A)
This is the class definition for the MonthDay
public class MonthDay
{
}
__________________________
B)
MonthDay.java
public class MonthDay {
//Declaring instance variables
int month;
int day;
//Parameterized constructor
public MonthDay(int month, int day) {
super();
if (month < 1 || month > 12) {
throw new IllegalArgumentException(
\"** InValid.Month must be between 1-12 **\");
} else {
this.month = month;
}
if (day < 1 || day > 31) {
throw new IllegalArgumentException(
\"** Invalid.Month must be between 1-31 **\");
} else {
this.day = day;
}
}
}
_____________Thank You
