What these pieces of codes do is call the current day,month,year and uses the JOptionPane to collect the information from the user. Then it converts the month value to a string to present your birthdate, and compares the date of the current date to your provided birth date by checking a few of the following things:
- If (currentYear - year <= 17) you are younger than 18 and cannot gain access to the website.
- If (year >= 17) and (month <= currentMonth) and (day <= currentDay), you are above 18 and can gain access to the website
- But if (year >= 17) and (month <= currentMonth) and (day > currentDay), you are younger than 18 and cannot gain access to the website.
The current date is callled by using the Date and DateFormat utilities, then each integer is parsed using a delimiter, "l". These integers are then made into the values of currentYear, currentMonth and currentDay, which are compared to the user input values, year,month, and day. Excepting a tiny portion of the population that was born in the 12 hours between the current day and the next day, anyone younger than 18 cannot convert the boolean value "access" to "true", unless they lie.
No comments:
Post a Comment