Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that asks the user for the date ( month and the day ) and returns the number of that day in

Write a Java program that asks the user for the date (month and the day) and returns the number
of that day in a year. Assume that the year is not a leap year.
1) Create a Java enum class named MonthOfYear.
The constants for the enum will be the months of the year: JANUARY through DECEMBER.
2) Create a field for the enum which shold the days of the months.
Thus the field should be declared: private final int numDays;
3) Create a constructor in the enum to initialize the number of days in each month controlled by
the enum.
The constructor should initialize numDays with the number of days for each month of the year,
assuming we have no leap year
4) Add an accessor (getter) method named getNumDays () which will return an integer
specifying the number of days in the month.
The method will need to be public so other classes can invoke the accessor.
Add a method to main class to validate the name of a month. Users can often make typographical
errors when entering values at the keyboard. As such, effective programs should validate the input
provided and, if invalid, display a reasonable (concise and meaningful) error message and repeat the
prompt.
5) Create a validation method which accepts the string entered by the user to specify the month
the user wishes to know the number of days for and return true if a valid month or false if it is not.
a) The validation method should determine whether the string matches one of the constant
values for MonthOfYear enum by comparing the string to the enum constants.
b) The validation method should verify correctness of month name regardless of lower-case /
upper-case characters in the name of the month.
(A case insensitive comparison.)
6) Add a method to Main Class to determine the number of the day in a year, for the month and
the day entered by the user. Determine the total number of days in preceding months, using
MonthofYear enum class.
7) Add a method to Main Class to determine the month and the day, for the number of the day in
a year, entered by the user

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

Are BWS and RTS necessary evils for the legal system?

Answered: 1 week ago

Question

Are my points each supported by at least two subpoints?

Answered: 1 week ago