Problem Statement
You are designing a word processor which automatically expands a date entered in shorthand format (e.g. "8/28/03") into its full format (e.g. "August 28th, 2003"). The full format is explained below.
Create a class CompleteDate containing a method expand that takes a
The shorthand format of date shall be as follows:
"M/D/Y"
1) M, and D do not have leading zeros
2) M is an integer between 1 and 12 inclusive representing the month
3) D is an integer between 1 and 31 inclusive representing the day of the month
4) Y is an integer between 0 and 99 inclusive and will always be written as 2 digits (i.e. "00","94","09" are all valid Y values)
Month 1 corresponds to "January", month 2 corresponds to "February", and so forth.
The expanded format is the month's name, followed by a single space, followed by the expanded form of the day (no leading zeros), followed by a single comma, followed by a single space, followed by the four digit year. Month names are: "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", and "December". The day of the month has 2 letters added to it, depending on the ending. For days 1, 21, and 31, add "st". For days 2 and 22, add "nd". For days 3 and 23, add "rd". For all other days, add "th". The years range from 1970-2069, so notice that the year "70" is actually 99 years before the year "69". See examples for more clarification.
TopCoder will ensure that the date is valid. The number of days possible depends on the month. Days start at 1 and go to 30 for April, June, September, and November. They start at 1 and go to 31 for January, March, May, July, August, October, and December. Finally, they start at 1 and go to 28 in February, except in a year divisible by 4, in which case they go up to 29.
Definition
- Class:
- CompleteDate
- Method:
- expand
- Parameters:
- String
- Returns:
- String
- Method signature:
- String expand(String date)
- (be sure your method is public)
Constraints
- date will be formatted as: "M/D/Y" as described above, with no leading zeroes (except for the year if necessary).
- date will represent a valid date as described above.
Examples
"1/1/70"
Returns: "January 1st, 1970"
The first date possible.
"12/31/69"
Returns: "December 31st, 2069"
The last date possible.
"2/29/72"
Returns: "February 29th, 1972"
"1/11/03"
Returns: "January 11th, 2003"
Remember that 11, 12, and 13 all have "th" added to them.
"6/12/55"
Returns: "June 12th, 2055"
"1/23/45"
Returns: "January 23rd, 2045"
"12/7/82"
Returns: "December 7th, 1982"
"7/29/80"
Returns: "July 29th, 1980"
"12/21/87"
Returns: "December 21st, 1987"
"11/6/45"
Returns: "November 6th, 2045"
"1/19/50"
Returns: "January 19th, 2050"
"3/1/03"
Returns: "March 1st, 2003"
"4/1/03"
Returns: "April 1st, 2003"
"5/31/69"
Returns: "May 31st, 2069"
"8/9/10"
Returns: "August 9th, 2010"
"9/6/69"
Returns: "September 6th, 2069"
"10/31/31"
Returns: "October 31st, 2031"
"1/13/00"
Returns: "January 13th, 2000"
"1/12/01"
Returns: "January 12th, 2001"
"5/31/01"
Returns: "May 31st, 2001"
"12/31/03"
Returns: "December 31st, 2003"
"1/11/55"
Returns: "January 11th, 2055"
"1/2/03"
Returns: "January 2nd, 2003"
"1/3/00"
Returns: "January 3rd, 2000"
"12/31/69"
Returns: "December 31st, 2069"
"1/13/00"
Returns: "January 13th, 2000"
"3/20/69"
Returns: "March 20th, 2069"
"3/3/90"
Returns: "March 3rd, 1990"
"11/11/02"
Returns: "November 11th, 2002"
"1/1/70"
Returns: "January 1st, 1970"
"1/11/00"
Returns: "January 11th, 2000"
"8/11/95"
Returns: "August 11th, 1995"
"8/21/01"
Returns: "August 21st, 2001"
"1/23/97"
Returns: "January 23rd, 1997"
"2/2/32"
Returns: "February 2nd, 2032"
"1/1/00"
Returns: "January 1st, 2000"
"12/15/00"
Returns: "December 15th, 2000"
"9/3/43"
Returns: "September 3rd, 2043"
"1/12/01"
Returns: "January 12th, 2001"
"5/31/01"
Returns: "May 31st, 2001"
"12/31/03"
Returns: "December 31st, 2003"
"1/11/55"
Returns: "January 11th, 2055"
"1/2/03"
Returns: "January 2nd, 2003"
"1/3/00"
Returns: "January 3rd, 2000"
"12/31/69"
Returns: "December 31st, 2069"
"1/13/00"
Returns: "January 13th, 2000"
"3/20/69"
Returns: "March 20th, 2069"
"3/3/90"
Returns: "March 3rd, 1990"
"11/11/02"
Returns: "November 11th, 2002"
"1/1/70"
Returns: "January 1st, 1970"
"1/11/00"
Returns: "January 11th, 2000"
"8/11/95"
Returns: "August 11th, 1995"
"8/21/01"
Returns: "August 21st, 2001"
"1/23/97"
Returns: "January 23rd, 1997"
"2/2/32"
Returns: "February 2nd, 2032"
"1/1/00"
Returns: "January 1st, 2000"
"12/15/00"
Returns: "December 15th, 2000"
"9/3/43"
Returns: "September 3rd, 2043"
"1/12/01"
Returns: "January 12th, 2001"
"5/31/01"
Returns: "May 31st, 2001"
"12/31/03"
Returns: "December 31st, 2003"
"1/11/55"
Returns: "January 11th, 2055"
"1/2/03"
Returns: "January 2nd, 2003"
"1/3/00"
Returns: "January 3rd, 2000"
"12/31/69"
Returns: "December 31st, 2069"
"1/13/00"
Returns: "January 13th, 2000"
"3/20/69"
Returns: "March 20th, 2069"
"3/3/90"
Returns: "March 3rd, 1990"
"11/11/02"
Returns: "November 11th, 2002"
"1/1/70"
Returns: "January 1st, 1970"
"1/11/00"
Returns: "January 11th, 2000"
"8/11/95"
Returns: "August 11th, 1995"
"8/21/01"
Returns: "August 21st, 2001"
"1/23/97"
Returns: "January 23rd, 1997"
"2/2/32"
Returns: "February 2nd, 2032"
"1/1/00"
Returns: "January 1st, 2000"
"12/15/00"
Returns: "December 15th, 2000"
"9/3/43"
Returns: "September 3rd, 2043"