cover picture cover picture


Homework 4

CMP 167: Programming Methods I
Lehman College, City University of New York
Spring 2016


This Homework Is Due By 11:59 PM on Tuesday March 15, 2016

In your textbook, this homework problem is in section 3.17 Homework 4-1.

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.