Logical expression
Consider the following method:
static boolean freeAccess (final DayOfWeek day, final int age) {
if (age <= 12) {
return true;
} else {
switch (day) {
case WEDNESDAY: return true;
default: return false;
}
}
}
Re-write this method using neither if ...
else
nor switch (...) {...}
but just a
single return
statement based on logical
expressions.
Write down only the return ... ;
statement using the text field below.
Solution
Free access is being granted if your age is less than or equal to 12 years or on Wednesdays:
return age <= 12 || DayOfWeek.WEDNESDAY == day;