Turning on and off power to an electromagnet is trivial.
Navigating a course autonomously is not.
What do you have working now?
You yelled in the title about needing help soon. What is the timeframe of your assignment?
You mention a 9v battery for power. If you are referring to a smoke detector battery, you will likely be disappointed in the very short run time. Be prepared to consider a better battery.