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
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
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

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

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

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education