When you move toward a stationary light source, the wavelength of the light emitted by the source decreases. In fact, it decreases according to the following formula:
w1 = w0*( 1 - v/c0 )
where w0 is the wavelength of the color emitted by the light source ( that is, as seen by a non-moving observer ), w1 is the wavelength of the color of the emitted light as perceived by you while you’re moving toward the source, v is the speed at which you’re moving toward the source ( assume speed is expressed as miles per hour ), and c0 is the speed of light ( assume light travels 669,600,000 miles per hour ). This phenomenon is known as ‘Doppler shift’, in honor of the Austrian mathematician Johan Christian Doppler ( 1803 – 1853 ).
The wavelength of green light is shorter than that of red light. This means that as you approach a red light, the color of the light shifts toward the green spectrum.
Now suppose a police officer stops you for running a red light. Clever person that you undoubtedly are, you argue that as you approached the light, the Doppler shift caused the red light to look green to you. Compassionate person that the officer is, he agrees to write you a ticket for speeding, instead of writing one for running the light. In the particular town in which you committed the infraction, the fine for running a red light is $100, and the fine for speeding is $1 for every mile per hour you travel over the speed limit. The speed limit is 25 miles per hour. Write a program that uses the above formula to calculate and display your speeding fine. You’ll need to solve the equation above for v, your speed as you approached the traffic signal. Use .533 microns for the wavelength of green light and .674 microns for the wavelength of red light. Display your fine as currency ( dollars and cents ).