Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following boolean expression: In most states, a vehicle must stop at a

ID: 3664728 • Letter: W

Question

Write the following boolean expression: In most states, a vehicle must stop at an intersection with a traffic light when the traffic light is red, except when making a right turn, in which case the driver must pause and can then make a right turn on red if the way is clear, unless otherwise posted. At a particular intersection there is a sign that says, "No right turn on red, 6am to 6pm, except Saturdays and Sundays." Write the complete set of rules and conditions for stopping at this intersection as a set of nested if/else instructions with Boolean expressions.

Explanation / Answer

if (signal_is_green == true)
{
print " The vehicle can pass"
}
else if ( signal_is_red == true )
{
if(no_right_turn_on_red == true)
{
if (day == sunday || day == saturday) // || stands for logical or
{
print "The vehicle can pass after a pause"
}

else if(time < 6 am && time > 6 pm) // && stands for logical AND
{
print "The vehicle can pass after a pause"
}

else

{

print " The vehicle can not pass"

}
}

}

else
{
print "The vehicle can not pass"
}