e if statement, and we want to use an exception to check the right input with if-else and how it works

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 9PE
icon
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.
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
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Header Files
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT