FontysICT-sem1

#Training Traffic Light

We are going to program traffic lights (popularly known as stop lights). Now it’s a pretty straightforward variant, but after theory in later chapters it will be extended. So save the code you create!

Analysis

Before we start typing code we always think about what we want to achieve:

Design

Realization.

A Console app has a mainmethod (public static void Main(string [] args)) in which you can put code like:

TrafficLight trafficLight = new TrafficLight();
// color has to be "Red".
Console.WriteLine(trafficLight.GetCurrentcolor());
trafficLight.NextState();
// color has to be "green".
Console.WriteLine(trafficLight.GetCurrentColor());
trafficLight.NextState();
// color has to be "orange".
Console.WriteLine(trafficLight.GetCurentColor());
trafficLight.NextState();
// and 'red' again!
Console.WriteLine(trafficLight.GetCurentColor());

The above code is somewhat sloppily put together: check for errors! Correct them if necessary and test the program. Can you think of any improvements to the program?