CJCoding With Joseph

Encapsulated State Machine

Build a class TrafficLight that hides its current color in a private string starting at "Red". Next() advances the color through the cycle Red -> Green -> Yellow -> Red -> ... A read-only Current property returns the color. Do not write a Main method.

Starting at Red, after one Next() the program prints:
Green

Expected Output:

Green
Topics:
Encapsulation
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.