Due: Friday, February 5, 1999
The most common system for enumerating the days of the year in use around the world today is the Gregorian calendar. It was adopted by Catholic countries upon the decree of Pope Gregory XIII in the year 1582. This system was devised by astronomer Christopher Clavius.
There are 12 months in the Gregorian calendar. All months save February always have the same number of days.
Month | Days |
---|---|
January | 31 |
February | 28 or 29 |
March | 31 |
April | 30 |
May | 31 |
June | 30 |
July | 31 |
August | 31 |
September | 30 |
October | 31 |
November | 30 |
December | 31 |
In a leap year the month of February has 29 days. A year that is exactly divisible by 4 is a leap year, except for years that are exactly divisible by 100 but not by 400. Thus the years 1988, 1992 and 1996 are leap years. And the year 2000 is a leap year, but 1900 and 2100 are not.
The system of numbering years from the birth of Christ was instituted in the year 525 by the Roman abbot Dionysius Exiguus. Years since the birth of Christ are said to be "A.D" for Anno Domini ("in the year of our Lord"). Years before the birth of Christ are said to be "B.C." ("before Christ"). However, for the purposes of this project, we will follow the astronomical practice of numbering years before the year 1 with non-positive numbers. So the year 1 B.C. is simply the year 0, and the year 2 B.C. is simply the year -1, etc.
-2 3 B.C. -1 2 B.C. 0 1 B.C. 1 1 A.D. 2 2 A.D.This has the advantage that the years 0, -4, -8, and so on are leap years in the proleptic calendar. (Actually, the Romans of that time were not systematically following this leap year rule or even their own leap year rule.)
Write a Java program NextDate that reads the month, day and year line by line from the standard input. Regard the input as a date in the proleptic Gregorian calendar. Print the next date. A "good" input line will be two positive numbers followed by an integer separated by spaces. But not all good data corresponds to a legal date in the Gregorian calendar. Legal years will be in at least the range from -5000 to 5000. (This means your program must work for all years in this range, it may work for other years, and it need not check if the year is in the range or not.)
Use the Java class StringTokenizer from the java.util package. It is then easy to allow all the numbers in the input to be separated by white space. The definition of an integer is whatever is used by parseInt
For example,
12 31 1996 ;; December 31, 1996 January 1, 1997
11 30 1997 ;; November 30, 1997 December 1, 1997
2 28 1999 ;; February 28, 1997 March 1, 1999
Check the input date to make sure it is legal. If it is not, then print an error message following these examples:
2 31 1996 Illegal date.
20 56 1996 Illegal date.
12 1996 Bad input line.
-12 31 1996 Bad input line.
2 31 Year Bad input line.A line with nothing in it is also a bad line (not an illegal date). If, after the date, additional characters are in the line, then you may or may not consider it a bad input line.
There should be the same number of output lines as input lines. Do not echo print the input; do not print blank lines.
Use the following command on malestrom.cs.fit.edu or zach.cs.fit.edu
~ryan/bin/mfiles ryan@cs.fit.edu "cse4510/lab05" NextDate.java
Be sure your name is in comments somewhere at the beginning of each Java file you submit. With luck a summary of the submissions for this lab exercise will be found in the file lab05-sub.txt.