I would like to know how to use the result of a boolean method in another method. The code below contains two methods, one named ValidateDay
and another called IsLeapYear
. IsLeapYear
determines if a user entered integer is a leap year. ValidateDay
checks if the day a user enters is a valid day based on what number month the user entered. In order the check if Feb 29th is a valid day, I need the ValidateDay
method to know if the result of IsLeapYear
is true or false. However, I am not sure how to reference the return value of IsLeapYear
in the ValidateDay
method. Any advice would be greatly appretiated.
// Determines if day is valid
public Boolean ValidateDay()
{
IsLeapYear();
if(Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12)
{
if (Day >= 1 && Day <= 31)
{
return true;
}
else
{
return false;
}
}
else if (Month == 4 || Month == 6 || Month == 9 || Month == 11)
{
if (Day >= 1 && Day <= 30)
{
return true;
}
else
{
return false;
}
}
else if (Month == 2 && IsLeapYear(true))
{
if (Day >= 1 && Day <= 29)
{
return true;
}
else
{
return false;
}
}
else if (Month == 2 && IsLeapYear(false))
{
if (Day >= 1 && Day <= 28)
{
return true;
}
else
{
return false;
}
}
}
// Determine if year is a leap year
public Boolean IsLeapYear()
{
if ((Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0))
{
return true;
}
else
{
return false;
}
}
Aucun commentaire:
Enregistrer un commentaire