Question: Write a program in java that simulates the conditions you may find at a traffic light. The program should prompt the user to enter a

Write a program in java that simulates the conditions you may find at a traffic light.The program should prompt the user to enter a value of either G, Y, or R that correspond to a green, yellow, or red light respectively.However, in the case of a yellow light the program should also prompt the user to check for a police presence by entering avalue of Y or N for yes or no.If there are no police in sightthen proceed through the light,otherwise come to a complete stop to avoid a ticket.
This program should use the if-else statement structure. Include all four different conditions related to the stoplight and a potential police presence and an example of invalid input. Include an switch statement version of this if-else statement as well please!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!