samedi 31 août 2019

How to make conditions that depends on one statement

So I got this homework to build a contactor for a class Date, check whether the data is valid, and in my checks, I should consider the possibility of a leap year. so I got the variable IsValidInJan:

 boolean IsValidInJan = month != 8 || 
 (year % 4 == 0 && year % 100 != 0 &&  year % 400 == 0);

and then I have an if statement that checks out whether the data is invalid (note that the body of the if statement should be activated if the data is invalid, and not the other way around)

if(year > current_year || (daysByMonth[month] < day && !IsValidInJan)|| day < 0 )

ignore the most of it. the thing is that inside the brackets (at the middel of the if stament) i want the following condtional logic:

if !IsValidInJan is true, then the whole stament is true (only inside the brackets)

if !IsValidInJan is false, then check if daysByMonth[month] < day is true or not and take that as the result (only inside the brackets)

I don't want to separate it to smaller if statement.

How can I achieve such logic?

Aucun commentaire:

Enregistrer un commentaire