Problem Statement
You will also be given an
The weekdays, in order, are: "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY".
The months of the year, in order are: "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER".
Definition
- Class:
- SpecialDay
- Method:
- howMany
- Parameters:
- String, int, String, int
- Returns:
- int
- Method signature:
- int howMany(String weekday, int which, String month, int day)
- (be sure your method is public)
Notes
- January 1st, 2000 is on a Saturday.
- January, March, May, July, August, October and December have 31 days.
- April, June, September and November have 30 days.
- February has 28 days unless it is a leap year wherein it has 29 days.
- A leap year is a year that is divisible by 4, unless it is also divisible by 100 and not 400.
Constraints
- day will be between 1 and the number of days in month, inclusive.
- which will be between 1 and 5, inclusive.
- weekday will be one of the following: {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"}
- month will be one of the following: {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"}
Examples
"THURSDAY"
4
"NOVEMBER"
23
Returns: 14
Here we are asked to calculate the number of times a person born on November 23rd has a birthday on Thanksgiving. When the 4th THURSDAY of NOVEMBER is also the 23rd of NOVEMBER it will be one of the following years: 2000, 2006, 2017, 2023, 2028, 2034, 2045, 2051, 2056, 2062, 2073, 2079, 2084 or 2090.
"MONDAY"
1
"SEPTEMBER"
2
Returns: 14
"SUNDAY"
2
"MAY"
13
Returns: 15
Here we are asked to calculate the number of times a person born on May 13th has a birthday on Mother's Day. When the 2nd SUNDAY of MAY is also the 13th of MAY it will be one of the following years: 2001, 2007, 2012, 2018, 2029, 2035, 2040, 2046, 2057, 2063, 2068, 2074, 2085, 2091 or 2096.
"SUNDAY"
3
"JUNE"
18
Returns: 14
"MONDAY"
3
"JANUARY"
16
Returns: 14
"MONDAY"
3
"APRIL"
15
Returns: 14
"TUESDAY"
5
"FEBRUARY"
29
Returns: 4
Watch out for leap years!
"MONDAY"
2
"OCTOBER"
6
Returns: 0
This scenario is impossible as the 2nd MONDAY cannot be on the 6th day of the month. It can only be on the 8th through the 14th, inclusive.
"THURSDAY"
3
"OCTOBER"
20
Returns: 14
"MONDAY"
5
"FEBRUARY"
29
Returns: 3
"SUNDAY"
1
"JANUARY"
1
Returns: 14
"MONDAY"
1
"FEBRUARY"
2
Returns: 15
"TUESDAY"
1
"MARCH"
3
Returns: 14
"WEDNESDAY"
1
"APRIL"
4
Returns: 15
"THURSDAY"
1
"MAY"
5
Returns: 14
"FRIDAY"
1
"JUNE"
6
Returns: 15
"SATURDAY"
1
"JULY"
7
Returns: 15
"SUNDAY"
2
"AUGUST"
8
Returns: 15
"MONDAY"
2
"SEPTEMBER"
9
Returns: 14
"TUESDAY"
2
"OCTOBER"
10
Returns: 14
"WEDNESDAY"
2
"NOVEMBER"
11
Returns: 14
"THURSDAY"
2
"DECEMBER"
12
Returns: 14
"FRIDAY"
2
"JANUARY"
13
Returns: 14
"SATURDAY"
2
"FEBRUARY"
14
Returns: 15
"SUNDAY"
3
"MARCH"
15
Returns: 14
"MONDAY"
3
"APRIL"
16
Returns: 15
"TUESDAY"
3
"MAY"
17
Returns: 14
"WEDNESDAY"
3
"JUNE"
18
Returns: 15
"THURSDAY"
3
"JULY"
19
Returns: 15
"FRIDAY"
3
"AUGUST"
20
Returns: 15
"SATURDAY"
3
"SEPTEMBER"
21
Returns: 14
"SUNDAY"
4
"OCTOBER"
22
Returns: 14
"MONDAY"
4
"NOVEMBER"
23
Returns: 14
"TUESDAY"
4
"DECEMBER"
24
Returns: 14
"WEDNESDAY"
4
"JANUARY"
25
Returns: 14
"THURSDAY"
4
"FEBRUARY"
26
Returns: 15
"FRIDAY"
4
"MARCH"
27
Returns: 14
"SATURDAY"
4
"APRIL"
28
Returns: 15
"SUNDAY"
5
"MAY"
29
Returns: 14
"MONDAY"
5
"JUNE"
30
Returns: 15
"TUESDAY"
5
"JULY"
31
Returns: 15
"MONDAY"
4
"FEBRUARY"
2
Returns: 0
"SATURDAY"
1
"SEPTEMBER"
18
Returns: 0
"TUESDAY"
3
"OCTOBER"
27
Returns: 0
"THURSDAY"
4
"DECEMBER"
28
Returns: 14
"SATURDAY"
5
"JANUARY"
29
Returns: 15
"MONDAY"
4
"FEBRUARY"
28
Returns: 15
"FRIDAY"
1
"JANUARY"
1
Returns: 14
"FRIDAY"
5
"FEBRUARY"
29
Returns: 4
"MONDAY"
4
"FEBRUARY"
29
Returns: 0
"MONDAY"
1
"MARCH"
1
Returns: 15
"SUNDAY"
2
"MAY"
13
Returns: 15
"SATURDAY"
1
"SEPTEMBER"
4
Returns: 15