CMIS 141
Write a program to display a calendar for any month of any year of the
twentieth century and on.
User enters the month number (must be between 1 and 12) and the year
(must be 1900 or later).
Example, say month 2 and year 2002 are input, then this is displayed
in a JTextArea in a JOptionPane:
February 2002
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28
--------------------------------------------------------
To determine the day of the week on which the month starts: know that
January 1, 1900 was a Monday, and then find the number of days
difference between that day and the first day of the month for which
you are making the calendar. This difference plus one mod 7
(i.e. (totaldays+1) % 7) tells you the day of the week (0 meaning
Sunday, 1 meaning Monday etc.). Finding the number of days from
1/1/1900 to the first day of any other month can be further broken
down into the following subproblems:
1. Number of days in whole years (i.e., (Year - 1900) * 365);
2. One day for each year in the above range which is a leap year;
3. The number of days in each month from January thru the previous
month of the year you're making a month calendar for.
Your program must use this technique to determine the start day of the
month.
Remember the rule for leap years: A year is a leap year if it is
divisible by 4, unless it is divisible by 100 (in which case it's not
a leap year) UNLESS it's also divisible by 400 (in which case it's a
leap year). year%4==0 && year%100!=0 || year%400==0 (1900 was not a
leap year, but 2000 is, 2100 will not be).
The program's overall structure will be something like:
input a valid month number,
input a valid year number,
calculate the total number of days since 1900-1-1,
append the month days to a JTextArea,
Displaying the dates hint: have a loop that displays the blank days
of the first week, then have a loop that loops over the days 1 to 30
(or 31, 28, or 29) The end of the week is when the date plus the
number of blank days is a multiple of 7.