e if statement, and we want to use an exception to check the right input with if-else and how it works
e if statement, and we want to use an exception to check the right input with if-else and how it works
Chapter2: Using Data
Section: Chapter Questions
Problem 9PE
Related questions
Question
We have if statement, and we want to use an exception to check the right input with if-else and how it works
![Task:
Write a program that converts dates from numerical month/day/year format to normal “month day,
year" format (for example, 12/25/2021 corresponds to December 25, 2021). You will define three
exception classes, one called MonthException, another called DayException, and a third
called YearException. If the user enters anything other than a legal month number (integers from
1 to 12), your program will throw and catch a MonthException and ask the user to reenter the
month. Similarly, if the user enters anything other than a valid day number (integers from 1 to either
28, 29, 30, or 31, depending on the month and year), then your program will throw and catch a
DayException and ask the user to reenter the day. If the user enters a year that is not in the range
1000 to 3000 (inclusive), then your program will throw and catch a YearException and ask the
user to reenter the year. (There is nothing very special about the numbers 1000 and 3000 other than
giving a good range of likely dates.)
In the main program, you will ask user to enter the date in MM/DD/YYYY format and then print
the formatted date if user enters the valid date.
[Hint: Use StringTokenizer class to parse the date input by user. Read some stuff about
StringTokenizer here https://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html]
The picture below represents the smaple console output.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6ed30014-755e-4ef8-aaaf-24d196ef5b56%2F7c1f1a6b-aeb5-490d-9a18-5cc852af7d21%2F1n82pw_processed.png&w=3840&q=75)
Transcribed Image Text:Task:
Write a program that converts dates from numerical month/day/year format to normal “month day,
year" format (for example, 12/25/2021 corresponds to December 25, 2021). You will define three
exception classes, one called MonthException, another called DayException, and a third
called YearException. If the user enters anything other than a legal month number (integers from
1 to 12), your program will throw and catch a MonthException and ask the user to reenter the
month. Similarly, if the user enters anything other than a valid day number (integers from 1 to either
28, 29, 30, or 31, depending on the month and year), then your program will throw and catch a
DayException and ask the user to reenter the day. If the user enters a year that is not in the range
1000 to 3000 (inclusive), then your program will throw and catch a YearException and ask the
user to reenter the year. (There is nothing very special about the numbers 1000 and 3000 other than
giving a good range of likely dates.)
In the main program, you will ask user to enter the date in MM/DD/YYYY format and then print
the formatted date if user enters the valid date.
[Hint: Use StringTokenizer class to parse the date input by user. Read some stuff about
StringTokenizer here https://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html]
The picture below represents the smaple console output.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT