Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that prompts the user to enter a person's date of birth through the command line, gathering the year, month, and day sequentially
Write a program that prompts the user to enter a person's date of birth through the command line, gathering the year, month, and day sequentially in that specific order. The application must accurately convert and display in a long format, such as "August To ensure robustness and reliability, your application must include at least two custom exception classes: invalidDay and invalidMonth, to handle erroneous day and month inputs respectively. Requirements: Sequential Input Collection: Year: Initially, prompt the user to enter the birth year. Validate this input to ensure it's a nonnegative integer. Should the user enter an invalid year eg a negative number the program should not proceed or crash but instead prompt the user again until a valid year is entered. Month: Next, request the month of birth as a numeric value through If the input falls outside this range, throw and catch an invalidMonth exception. This exception handling should guide the user back to entering a correct month number. Day: Finally, prompt for the day of birth. The validity of the day depends on the entered month and year considering leap years for February If an incorrect day is provided, throw and catch an invalidDay exception, and inform the user of the acceptable day range for the specified month and year. Custom Exception Handling: invalidDay Exception: This exception is triggered if the user inputs an invalid day based on the month and year eg "February It should convey a clear error message to the user, indicating the valid day range. invalidMonth Exception: Triggered by an outofrange month input, this exception should prompt the user to input a valid month number Accurate Leap Year Calculation: Implement logic to determine whether the specified year is a leap year, impacting the valid date range for February. Verbose Date Output: Upon validating all inputs year month, day the application should display the date of birth in a clear, verbose format eg converting into "August Suggestions for Implementation: Utilize trycatch blocks to manage input validation and to provide feedback for incorrect inputs, ensuring the program remains userfriendly and resilient against invalid data. Apply conditional logic eg switch or ifelse statements to translate numeric month values into their corresponding month names. A year is a leap year if it is divisible by except for years that are both divisible by and not divisible by This calculation is critical for accurately determining the number of days in February.
Write a program that prompts the user to enter a person's date of birth through the command line, gathering the year, month, and day sequentially in that specific order. The application must accurately convert and display in a long format, such as "August To ensure robustness and reliability, your application must include at least two custom exception classes: invalidDay and invalidMonth, to handle erroneous day and month inputs respectively.
Requirements:
Sequential Input Collection:
Year: Initially, prompt the user to enter the birth year. Validate this input to ensure it's a nonnegative integer. Should the user enter an invalid year eg a negative number the program should not proceed or crash but instead prompt the user again until a valid year is entered.
Month: Next, request the month of birth as a numeric value through If the input falls outside this range, throw and catch an invalidMonth exception. This exception handling should guide the user back to entering a correct month number.
Day: Finally, prompt for the day of birth. The validity of the day depends on the entered month and year considering leap years for February If an incorrect day is provided, throw and catch an invalidDay exception, and inform the user of the acceptable day range for the specified month and year.
Custom Exception Handling:
invalidDay Exception: This exception is triggered if the user inputs an invalid day based on the month and year eg "February It should convey a clear error message to the user, indicating the valid day range.
invalidMonth Exception: Triggered by an outofrange month input, this exception should prompt the user to input a valid month number
Accurate Leap Year Calculation: Implement logic to determine whether the specified year is a leap year, impacting the valid date range for February.
Verbose Date Output: Upon validating all inputs year month, day the application should display the date of birth in a clear, verbose format eg converting into "August
Suggestions for Implementation:
Utilize trycatch blocks to manage input validation and to provide feedback for incorrect inputs, ensuring the program remains userfriendly and resilient against invalid data. Apply conditional logic eg switch or ifelse statements to translate numeric month values into their corresponding month names. A year is a leap year if it is divisible by except for years that are both divisible by and not divisible by This calculation is critical for accurately determining the number of days in February.
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