Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that asks the user for a date entered as 4 integers: dayNumber monthNumber date year . Where: dayNumber An integer from

Write a Java program that asks the user for a date entered as 4 integers: dayNumber monthNumber date year. Where:

dayNumber

An integer from 1-7, where 1 = Sunday, 2 = Monday, ..., 7 = Saturday

monthNumber

An integer from 1-12, where 1 = January, 2 = February, ..., 12 = December

date

An integer from 1-31 representing the date.

year

An integer representing the year.

Your prompt to the user should be:

 Enter 4 integers representing dayNumber monthNumber date year: 

You program will compute the proper dayName from the specified dayNumber and the proper monthName from the specified monthNumber. Your program will print out the specified date in the following format:

 dayNumber monthNumber date year is dayName monthName date, year 

Please note your program will have to error check the input as follows:

Please note your program will have to error check the input as follows:

  1. First the dayNumber is checked for being in the range 1..7. If that is not the case, your program should print out the following message and terminate execution:
     Invalid day number: dayNumber, please enter a number from 1..7. 
  2. Then the monthNumber is checked for being in the range 1..12. If that is not the case, your program should print out the following message and terminate execution:
     Invalid month number: monthNumber, please enter a number from 1..12. 
  3. Then the date is checked for being in the range 1..31. If that is not the case, your program should print out the following message and terminate execution:
     Invalid date number: date, please enter a number from 1..31. 
  4. Then the date must be checked for validity. For example, there is no February 30, February 31, April 31, June 31, September 31, November 31. If the date is invalid, your program should print out the following message and terminate execution:
     Invalid date: monthName, does not have date days, please enter a valid date. 
  5. Lastly, if the monthNumber = 2, and date = 29 you must verify that the year entered is a leap year, which is the only time that February 29 exists. Please see Wikipidia's Page on Leap Year. If the year is not a leap year and the user entered a date = 29, your program should print out the following message and terminate execution:
     Invalid date: year is not a leap year, February does not have date days, please enter a valid date. 

Please note that your class should be named DateConverter.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions