Question: Write a class named Month based on the UML class diagram shown ABOVE. Class Month will need an integer instance field named monthNumber that holds

 Write a class named Month based on the UML class diagram

Write a class named Month based on the UML class diagram shown ABOVE.

Class Month will need an integer instance field named monthNumber that holds the number of the month (For example, 1 is January, 2 is February, etc.)

A static String array may be used to hold the names of the month: "January", "February", etc.

Include two constructor methods

1. A constructor method that accepts an integer argument from 1..12 corresponding to the month number .

The method should throw an IllegalArgumentException if the number passed in is outside the range 1..12.

Set the exception error message to "Illegal month number: " followed by the illegal value passed in

2. A constructor method that accepts a String argument. The argument may take the form "1" or "2", etc. or "January", "February", etc.

The method should throw an IllegalArgumentException if the String Program 5 passed in is not between "1" .. "12" or not "January", "February", etc.

Ignore casing, so "JANUARY" or "janUary" should be considered equivalent to "January"

Include two setter methods

1. setMonthNumber that accepts an integer argument between 1..12. Throw an IllegalArgumentException if the parameter value is outside the range 1..12

2. setMonthName that accepts a String argument "January", "February", etc. Throw an IllegalArgumentException if the parameter is not "January", "February", etc. Ignore casing, so "JANUARY" or "janUary" should be considered equivalent to "January"

Include two getter methods

1. getMonthNumber that returns an integer value 1..12 corresponding to the month object

2. getMonthName that returns a String value "January", "February", etc. corresponding to the month object

A toString method that returns the month's name "January", "February", etc.

A equals method that returns true if the Month argument share the same month, false otherwise

A next method that returns a Month object set to the next month. For example, a February Month object would return a March Month object

Note: calling next() on a December Month object should return a January Month object

A previous method that returns a Month object set to the previous month. For example, a February Month object would return a January Month object

Note: calling previous() on a January Month object should return a December Month object

Month jGRASP UML class diagram SHOWN BELOW

shown ABOVE. Class Month will need an integer instance field named monthNumber

Note: method is automatically generated to create the private static String [] for monthNames private static String[] monthNames = {"January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November", "December"};

Unit testing the Month class Constructor method and getter method unit tests

that holds the number of the month (For example, 1 is January,

Constructor method exceptions thrown

Month m4 = new Month(13)

Exception in evaluation thread

java.lang.IllegalArgumentException: Illegal month number: 13

Month m5 = new Month("Saturday")

Exception in evaluation thread

java.lang.IllegalArgumentException: Invalid month name: Saturday

Month m5 = new Month("Jan")

Exception in evaluation thread

java.lang.IllegalArgumentException: Invalid month name: Jan

Month m5 = new Month("-1")

Exception in evaluation thread

java.lang.IllegalArgumentException: Illegal month number: -1

Month m5 = new Month("13")

Exception in evaluation thread

java.lang.IllegalArgumentException: Illegal month number: 13

Setter method unit tests

2 is February, etc.) A static String array may be used to

Setter method exceptions thrown

m1.setMonthNumber(0)

Exception in evaluation thread

java.lang.IllegalArgumentException: Illegal month number: 0

m1.setMonthName("Fall")

Exception in evaluation thread

java.lang.IllegalArgumentException: Invalid month name: Fall

equals, next, previous method unit tests

hold the names of the month: "January", "February", etc. Include two constructor

Main method demo class

Write a MonthDemo class that contains a main method with a try.catch construct to

Prompt the user to enter a month (as a String). Allow the user to enter the string "1", "2", etc. or "January", etc.

try to create the Month object, passing in the user input (as a string) o catch any exception thrown from the constructor method o display the exception object's error message o re-prompt the user to enter a month (until they get it right)

Display the month entered (use the Month object's toString method

MonthDemo main method

methods 1. A constructor method that accepts an integer argument from 1..12

GET THE PROGRAM TO RUN WITH CORRECT DATA THEN WORRY ABOUT THE EXCEPTION HANDLING

What to turn in

Your program will be graded directly online. No source printout is required.

For this Assignment, I want a NetBeans Complete Project

UNIT TESTING OUTPUT

corresponding to the month number . The method should throw an IllegalArgumentException

Month monthNumber int monthNames StringDE ("January"... Month (m int) Month (s String) setMonthNumber (m int) void setMonthName (name String) void get MonthNumber 0 int getMonthName 0 String toString0 String equals(m Month) boolean next0 Month previous0 Month

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!