When the StopWatch State Machine enters the ready State, the elapsed time defined by the attribute time: Integer should be reset to zero. In addition, the elapsed time should increment by 1 every second while the StopWatch is in the running state. You can define this functionality using Alf in two Operations on the StopWatch Class: resetTime and increaseTime. These operations will later be called from the entry Behaviors of the appropriate states in the StopWatch State Machine.
To create the resetTime Operation
- Right-click the StopWatch class in the Model Browser and select Create Element > Operation.
- Name the new operation resetTime (see the following figure).
- While resetTime operation is selected, open the Alf editor window (select Windows > Alf), if it isn't already open, and press Create.
Enter the Alf code shown in the figure below.
- When the Alf code is correct, press Save.
To create the increaseTime Operation
- Right-click the StopWatch class in the Model Browser and select Create Element > Operation.
- Name the new operation increaseTime.
Click on the increaseTime operation and, in the Alf editor window, press Create.
Enter the Alf code shown in the figure below.
- When the Alf code is correct, click Save.
Related pages