Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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.
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education