Tesla Interview Question

How to implement a state machine.