Answered step by step
Verified Expert Solution
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.
Create a Java enum class named MonthOfYear.
The constants for the enum will be the months of the year: JANUARY through DECEMBER.
Create a field for the enum which shold the days of the months.
Thus the field should be declared: private final int numDays;
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
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.
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 lowercase
uppercase characters in the name of the month.
A case insensitive comparison.
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.
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started