Problem Statement
You are a big fan of New Year's Eve parties. The next one is not too far away, and you are already looking forward to it.
Then, one day, you wake up with a question: "Wait a moment, exactly how far away is it?"
To answer this question, you decided to implement a simple application: a year progress bar that will always show how much of the current year has already passed.
In this problem, your goal is to implement the most important part of this application: a function that gets a
The variable currentDate will be of the form "Month DD, YYYY HH:MM" (quotes for clarity). Here, "Month" is the name of the current month, "YYYY" is a four-digit number representing the current year, and "DD", "HH", and "MM" are two-digit numbers (possibly with a leading zero) that represent the current day, hour and minute.
Definition
- Class:
- YearProgressbar
- Method:
- percentage
- Parameters:
- String
- Returns:
- double
- Method signature:
- double percentage(String currentDate)
- (be sure your method is public)
Notes
- The months of a normal year have 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, and 31 days.
- In leap years, the second month (February) has 29 days.
- A year is a leap year if (it is divisible by 400) or (it is divisible by 4, but not by 100).
- Ignore location-dependent changes to time flow such as daylight saving time.
- Your return value must have a relative or absolute error less than 1e-9.
Constraints
- currentDate will be of the form given in the problem statement.
- Month will be one of January, February, March, April, May, June, July, August, September, October, November, and December.
- YYYY will be between 1800 and 2600, inclusive.
- DD will be between 01 and the number of days in the given month (in the given year), inclusive.
- HH will be between 00 and 23, inclusive.
- MM will be between 00 and 59, inclusive.
Examples
"January 01, 2008 00:00"
Returns: 0.0
This is the exact beginning of the year 2008; no time has elapsed yet.
"December 31, 2007 23:59"
Returns: 99.99980974124807
One last minute of the year 2007 is remaining.
"July 02, 2007 12:00"
Returns: 50.0
The exact half of a normal year is at noon on the second day of July.
"July 02, 2008 00:00"
Returns: 50.0
On a leap year, the exact half of the year is the midnight between the first and the second of July.
"May 10, 1981 00:31"
Returns: 35.348363774733635
The date and time when the problem setter was born :-)
"January 31, 1900 00:47"
Returns: 8.228120243531203
Note that 1900 is not a leap year.
"January 11, 1800 09:46"
Returns: 2.8512176560121767
"February 20, 1900 07:53"
Returns: 13.788622526636225
"March 08, 2000 09:12"
Returns: 18.410746812386158
"April 02, 2100 19:02"
Returns: 25.148782343987822
"May 24, 2200 11:19"
Returns: 39.307267884322684
"June 17, 2300 18:00"
Returns: 45.95890410958904
"July 05, 2400 11:16"
Returns: 50.94793564055859
"August 02, 2500 21:27"
Returns: 58.601027397260275
"September 03, 2600 14:50"
Returns: 67.29261796042618
"October 20, 2548 17:55"
Returns: 80.25861414693382
"November 13, 2133 05:18"
Returns: 86.63584474885843
"December 23, 2296 19:16"
Returns: 97.76032179720706
"January 18, 1824 21:33"
Returns: 4.89014116575592
"February 08, 2417 14:37"
Returns: 10.57781582952816
"March 02, 1901 05:30"
Returns: 16.501141552511417
"April 17, 2566 20:20"
Returns: 29.273211567732112
"May 22, 2219 04:50"
Returns: 38.68531202435312
"June 02, 2076 20:45"
Returns: 42.03950364298725
"July 05, 2405 22:05"
Returns: 50.937024353120236
"August 03, 1804 12:17"
Returns: 58.883006982392224
"September 16, 2475 14:45"
Returns: 70.85331050228311
"October 27, 2243 03:44"
Returns: 81.96042617960426
"November 21, 2329 12:48"
Returns: 88.91324200913243
"December 01, 2498 03:24"
Returns: 91.54566210045661
"January 10, 2438 12:19"
Returns: 2.6063546423135464
"February 05, 2042 19:48"
Returns: 9.815068493150683
"March 19, 1816 06:06"
Returns: 21.38091985428051
"April 30, 1836 02:10"
Returns: 32.81155130540376
"May 12, 2591 17:21"
Returns: 36.0884703196347
"June 03, 1977 04:12"
Returns: 41.96575342465753
"January 01, 2400 00:01"
Returns: 1.8973891924711593E-4
"January 31, 2000 00:47"
Returns: 8.205639040680024
"February 02, 2007 12:00"
Returns: 8.904109589041095
"July 02, 2000 12:00"
Returns: 50.13661202185792
"July 02, 2300 12:00"
Returns: 50.0
"September 02, 2007 12:00"
Returns: 66.98630136986301
"March 10, 1900 12:05"
Returns: 18.768074581430746
"May 10, 2100 00:31"
Returns: 35.348363774733635
"January 01, 2008 00:10"
Returns: 0.0018973891924711599
"September 11, 2400 10:42"
Returns: 69.52071948998179
"November 20, 1900 23:55"
Returns: 88.76617199391171
"February 18, 2000 23:16"
Returns: 13.379629629629632
"January 12, 2000 00:00"
Returns: 3.0054644808743167
"March 01, 2000 00:00"
Returns: 16.39344262295082
"May 01, 2000 00:00"
Returns: 33.060109289617486
"December 31, 1900 23:59"
Returns: 99.99980974124807
"July 02, 2100 00:00"
Returns: 49.863013698630134
"November 20, 1900 00:00"
Returns: 88.4931506849315
"February 17, 1990 03:11"
Returns: 12.913051750380516
"February 12, 2004 10:34"
Returns: 11.595704310868244
"August 01, 2008 00:00"
Returns: 58.19672131147541
"February 15, 2008 12:07"
Returns: 12.433022161505768
"April 29, 1900 00:47"
Returns: 32.337709284627095
"January 23, 2000 23:23"
Returns: 6.277132665452337
"February 29, 2008 23:55"
Returns: 16.392493928354586
"January 12, 2004 10:34"
Returns: 3.125758955676988
"July 25, 2000 01:11"
Returns: 56.29762446873102
"August 09, 2007 00:34"
Returns: 60.28044140030441
"February 01, 2008 00:00"
Returns: 8.469945355191257
"November 30, 2000 23:59"
Returns: 91.52986490588947
"October 03, 2000 00:00"
Returns: 75.40983606557377
"March 13, 2000 14:51"
Returns: 19.841188524590162
"December 31, 2000 23:59"
Returns: 99.99981026108073
"December 31, 2200 23:59"
Returns: 99.99980974124807
"January 11, 2008 00:00"
Returns: 2.73224043715847
"April 25, 2000 11:23"
Returns: 31.55035670916818
"December 31, 2100 23:59"
Returns: 99.99980974124807