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 monthNumberto 1. An overloaded constructor that accepts the number of the month as an argument.  The constructor should set the monthNumberfield 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 monthNumberbased 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 The mutator method must validate the monthNumber parameter and throw an InvalidMonthException exception back to the caller when an invalid value is given. A getMonthNamemethod that returns the name of the month based upon the monthNumber A toString method that returns the same value as the getMonthName An equalsmethod 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 Develop a test client to thoroughly test the Month class and handle the exceptions thrown

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter11: Exception Handling
Section: Chapter Questions
Problem 5E
icon
Related questions
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 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 monthNumberto 1.
  • An overloaded constructor that accepts the number of the month as an argument.  The constructor should set the monthNumberfield 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 monthNumberbased 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 The mutator method must validate the monthNumber parameter and throw an InvalidMonthException exception back to the caller when an invalid value is given.
  • A getMonthNamemethod that returns the name of the month based upon the monthNumber
  • A toString method that returns the same value as the getMonthName
  • An equalsmethod 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

Develop a test client to thoroughly test the Month class and handle the exceptions thrown

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning