I am writing a method that is supposed to check whether or not someone is over 35. The method is given a birth date as a String (DD.MM.YYYY). This is exported from a different program, so I can't change that part. The method should return true, if the date given represents someone over 35
I would like to split that String using the "." as a separator and then parse the numbers to ints, making them comparable to the current date. Anyone turning 35 this quarter of the year will already be considered 35, even if the exact date is yet to come.
Here is the code so far:
My problem is that birhdateArray comes back empty. I would expect a String with the values (for example) birthdateArray==24, birthdateArray==5, and birthdateArray==1963 if birhtdate was set to "24.05.1963". Instead it is String with the value .
Where am I wrong?
Thank you for your help,
P.S.: In reading this I realize that currMonth and currYear are redundant. I will remove them, but they do not concern the question.
The problem people have in trying to create something foolproof is that they generally underestimate the inginuity of fools.
As an alternative, find classes like SimpleDateFormat, tell them to use DD.MM.YYYY and get the date directly from the String.
Joined: Oct 31, 2008
I did not know that, thank you! Like I said, the date format comes from outside. I am a physician, and it get's exported by my software at the office in this format. So I figured 2 or 3 more lines in the checkAge method are easier than changing the format.
This will solve my problem, though, so thanks everybody!