Description
Traffic Signal
Introduction
Make a traffic light in your computer using C#.
What you will learn or experience in this assignment
- How to declare an internal clock and set its speed.
2, How to attach a listener to a clock
- How to pause a clock and re-start a clock.
User Interface
In this course we make lots of user interfaces. During the technical phase of your future job interviews if you are asked what do you know about C# you are certainly qualified to say that “I made a lot of user interfaces”.
For this assignment make a form that will hold your traffic light. The traffic light appears to be embedded in the form. The following is an illustration of the traffic light inside the form. The example shows the red light “on”, and the yellow and green lights are “off”.
Only one light is on at any time. If the green light is on then the other two lights are grayed out.
Programming specifications
When the program starts the traffic light is off (no electricity).
When the user clicks on “Start” the traffic begins normal operations at the default speed “slow”, which is explained in the next paragraphs.
If the user clicks on “Pause” then the traffic light freezes. The traffic signal does not turn off the electricity; it simply pauses where it is. When “Pause” is clicked the string “Pause” on that button changes to “Resume”. When “Resume” is clicked the string “Resume” changes to the string “Pause”.
If the user clicks on “Resume” then the traffic signal begins operation from the point in time when operation was suspended.
At any time the user may change the speed (rate of change) by clicking on one of the radio buttons. Here are the rates for slow and fast operation. The numbers represent number of seconds each light is on.
| Red light | Green light | Yellow light | |
| Fast | 4.0 s | 3.0 s | 1.0 s |
| Slow | 8.0 s | 6.0 s | 2.0 s |
The table shows how many seconds the light remains ‘on’ in each mode of operation. For example, in the ‘Slow’ mode of operation the red light is on for 8 seconds, followed by the yellow light on for 2.0 second, followed by the green light ‘on’ for 6.0 seconds.
Comments in source code
Use the rules of Assignment 1 for placing comments in the source files of this program.
Script files
Make a script file for Assignment 2 in the same way as you did in the previous assignment. The script file is as much a part of the program as the C# source files are.
Comment about word processed documents.
If you are reading this document in Word the probability is high that the drawing of the traffic signal on page 2 will be distorted. The solution is to open document files like this one in Libre Office.
Check off list for evaluating Traffic Signal program
Source code
Written in C# with no evidence of Visual Studio
Program design partitions the solution into 2 and sometimes 3 files.
Comments identify the author, course, program, and purpose.
No meaningless residual comments remaining from one of professor’s programs.
Program compiles without warnings and without fatal errors.
The script file runs out of the box.
User Interface qualities
Program executes and shows a UI.
UI shows a title strip across the top with the program’s name and the author’s name
Outline of a traffic signal appears (3 circles)
The graphic area around the traffic signal has a distinguishing official highway color.
The control strip has a unique color
There are slow, medium, fast radio buttons in the control strip
There is a button labeled ‘Start’.
There is a button labeled ‘Pause’.
There is an Exit button
Run-time functionality
The signal does not function until the start button is clicked.
Visually the red light is longest, green is middle, yellow is shortest in duration.
No two lights are ‘on’ concurrently.
At least one light is ‘on’ at any given instant.
The user can change the speed of flashing without exiting from the program.
To test your timing: hold your cell phone with the clock displayed near your computer monitor. Run the program in slow mode. Check if the red light stays on exactly 8 seconds before changing to yellow.



