Replies To: date validation

Re: date validation

Posted 27 August 2009 - 07:27 AM

You should use just one function to determine if a date is valid, hence instead of having the function public boolean getDate() just have a function public boolean validate() and in the positions you set good = true; or good = false; simply return eg. return true; or return false;

As for why it is always returning false, that would be an issue with your if and if else statements, revise the statements and try simplifying it. Sometimes look at the other side of the coin and it may simplify your problem.

Re: date validation

I know that I cant use this.good = validate(); because it says that they are incompatible type but how would I set the value for the variable good using the validate method?

I got 2 true's when I changed those fields to "this" and ran the program. I don't have this in your DateRec function though, because it doesn't return anything (void).

this.good = validate();

But mine works and I cut and pasted your code and just added the this.'s. ...

Laythe, on 27 Aug, 2009 - 04:41 PM, said:

ok, so tell me what is year divided on 4 or 100 or 400 stands for, what is that mean so i may can help ye

That is how you tell if any given year is a "leap year" or not. The year 2000 wasn't suppose to be a leap year, but it happened to be divisible by 400, so we had a Feb. 29th that year!

I wasn't able to figure out how to validate the date using the method validate() and instantiate the variable good but I just decided to use a value-returning method to instead. It's not what my assignment calls for but it works.

I am having trouble with validating the month of February due to the leap year statments. I know that my if-else statements work correctly to return true or false when finding if a year is a leap year or not but my code accepts values for Feb. that shouldn't be valid. For instance, 2/29/2000 should return true and set the value for the variable good to true but the date 2/29/2001 should return false because that year is not a leap year, therefore there are only 28 days in Feb not 29. Any suggestions?