Problem

Visit www.myprogramminglab.com to complete select exercises online and get instant feedbac...

Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.

Exercise

Write a program that converts dates from numerical month/day/year format to normal “month day, year” format (for example, 12/25/2000 corresponds to December 25, 2000). 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.) See Self-Test Exercise for details on leap years.

Self-Test Exercise

Write a better version of the method dateOK with three int parameters (Display). This version should check for the correct number of days in each month and should not just allow 31 days in any month. It will help to define another helping method named leapYear , which takes an int argument for a year and returns true if the year is a leap year. February has 29 days in leap years and only 28 days in other years. Use the following rule for determining if the year is a leap year: A year is a leap year if it is divisible by 4 but is not divisible by 100, or if it is divisible by 400.

Display

Yet Another Date Class

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 9