Loading...
Loading...
Loading...
A driving-school app reads the signals a learner sees on the road and prints what to do at each one.
Declare enum Signal { RED, YELLOW, GREEN }. Turn each word into a constant with valueOf and pick the action with a switch expression: Stop, Slow down or Go.
SIGNAL -> action.Example
Input
3 RED GREEN YELLOW
Output
RED -> Stop GREEN -> Go YELLOW -> Slow down
Each name becomes a constant, and the switch picks its action.
Try the problem first. Open one hint at a time.
Signal s = Signal.valueOf(sc.next()); turns the word into a constant.
A switch expression with one case per constant needs no default.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor