Question: public class Exercise 0 2 _ CanDrive { / * The problems below ask you to implement the correct logic to answer whether someone is
public class ExerciseCanDrive
The problems below ask you to implement the correct logic to answer
whether someone is allowed to drive based on the provided parameters.
NOTE: These rules are loosely based off of the real world
and may be different from the state you live in
A person can drive if they have a permit and are with a licensed passenger.
Given two boolean values, hasPermit and withLicensedPassenger,
write an expression that is true if a person can drive.
Examples:
canDrivetrue true true
canDrivetrue false false
canDrivefalse true false
canDrivefalse false false
public boolean canDriveboolean hasPermit, boolean withLicensedPassenger
In some states, the licensed passenger must be of a certain age.
Implement the logic to return true if the person has a permit and is with a licensed passenger who is or over.
Examples:
canDrivetrue true, true
canDrivetrue true, false
canDrivefalse true, false
public boolean canDriveboolean hasPermit, boolean withLicensedPassenger, int passengerAge
If the licensed passenger is the driver's legal guardian, they only have to be instead of
Implement the logic to return true if the person has a permit and is with a licensed passenger.
The licensed passenger only needs to be or older if they're the driver's guardian. Otherwise, the passenger must be or older.
Examples:
canDrivetrue true, false true
canDrivetrue true, true true
canDrivefalse true, true false
public boolean canDriveboolean hasPermit, boolean withLicensedPassenger, int passengerAge, boolean isPassengerOurGuardian
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
