Question
Develop an exception class named InvalidMonthException that extends the Exception class. Instances of the class will be thrown based on the following conditions: The value
Develop an exception class named InvalidMonthException that extends the Exception class. Instances of the class will be thrown based on the following conditions:
The value for a month number is not between 1 and 12
The value for a month name is not January, February, March, December
Develop a class named Month. The class should define an integer field named monthNumber that holds the number of a month. For example, January would be 1, February would be 2, and so forth. In addition, provide the following methods:
A no-argument constructor that sets the monthNumber to 1.
An overloaded constructor that accepts the number of the month as an argument. The constructor should set the monthNumber field to the parameter value if the parameter contains the value 1 12. Otherwise, throw an InvalidMonthException exception back to the caller. The exception should note that the month number was incorrect.
An overloaded constructor that accepts a string containing the name of the month, such as January and sets the monthNumber based on the parameter string. When the parameter value does not match a valid name of a month, the constructor throws an InvalidMonthException exception back to the caller. The exception should note an invalid month name was used.
Accessor and mutator methods for the monthNumber field. The mutator method must validate the monthNumberparameter and throw an InvalidMonthException exception back to the caller when an invalid value is given.
A getMonthName method that returns the name of the month based upon the monthNumber field.
A toString method that returns the same value as the getMonthName method.
An equals method that accepts a Month object as a parameter and compares the object to the calling object to determine if the objects contain the same value for the monthNumber field.
Develop a test client to thoroughly test the Month class and handle the exceptions thrown.
Can you write this in java using jgrasp?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started