Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

image text in transcribed

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

image text in transcribed

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

image text in transcribed

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

image text in transcribed

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

image text in transcribed

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

What to turn in

NetBeans Complete Project

UNIT TESTING OUTPUT

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visualizing Health And Healthcare Data Creating Clear And Compelling Visualizations To See How Youre Doing

Authors: Katherine Rowell ,Lindsay Betzendahl ,Cambria Brown

1st Edition

1119680883, 978-1119680888

More Books

Students also viewed these Databases questions

Question

1.2 Describe who performs HRM.

Answered: 1 week ago

Question

What could the team have done to avoid the situation described?

Answered: 1 week ago

Question

Identify the types of informal reports.

Answered: 1 week ago

Question

Write messages that are used for the various stages of collection.

Answered: 1 week ago