Coding the switchHeading method