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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education