Question: Chapter 10 Starting Out With Java With Early Objects 4. Month Class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Month

Chapter 10 Starting Out With Java With Early Objects

4. Month Class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Month class that holds

information about the month. Write exception classes for the following error conditions:

A number less than 1 or greater than 12 is given for the month number.

An invalid string is given for the name of the month. Modify the Month class so it throws the appropriate exception when either of these errors

occurs. Demonstrate the classes in a program.

 Chapter 10 Starting Out With Java With Early Objects 4. Month

5. Month class Write a class named Month. 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 6 A Second Look at Classes and Objects .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" 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. . . A greaterThan method that accepts a Month object as an argument. If the calling object's monthNumber field is greater than the argument's monthNumber field, this method should return true. Otherwise, it should return false. .A lessthan method that accepts a Month object as an argument. If the calling object's monthNumber field is less than the argument's monthNumber field, this method should return true. Otherwise, it should return false

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!