Question: You are tasked with creating a Java program that converts dates from the numerical month / day / year format to the standard month day,
You are tasked with creating a Java program that converts dates from the numerical monthdayyear format to the standard "month day, year" format. For instance, the date should be converted to December Your program should also handle various exceptions that may occur due to invalid inputs.
Requirements:
Your program should continuously prompt the user to enter a date in the MMDDYYYY format until a valid date is entered.
Validate the user input to ensure that:
The month is between and
The day is within the appropriate range for the given month and year eg days for January, March, May, July, August, October, and December; days for April, June, September, and November; and or days for February depending on leap years
The year is between and
If the user enters an invalid date, display an appropriate error message and ask them to reenter the date.
Use exception handling to catch and handle the following exceptions:
NumberFormatException: Occurs when the input cannot be parsed as an integer.
ArrayIndexOutOfBoundsException: Occurs when the input does not contain enough parts month day, year
MonthException: Custom exception class for invalid month inputs.
DayException: Custom exception class for invalid day inputs.
YearException: Custom exception class for invalid year inputs.
Use the switch statement to convert the numeric month to its corresponding name eg to January, to February, etc.
Display the formatted date in the "month day, year" format when a valid date is entered.
Hints:
Use the Scanner class for user input.
Utilize a trycatch block for exception handling.
Implement a loop to continuously ask for the date until a valid date is entered.
Use the String.split or StringTokenizer method to separate the input into month, day, and year parts.
Sample Output:
Enter date in MMDDYYYY format:
Invalid month. Please enter a number between and
Enter date in MMDDYYYY format:
Invalid day. Please enter a number between and
Enter date in MMDDYYYY format:
Formatted date: February
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
