Exercise 4

1 When-statement

Let us go back to the class LightSwitch, that is initially switched off and switched on at time 5. Change this class to contain a when-statement instead of a when-equation.





Now change the
LightSwitch class so that it in the time interval 5-20 turns the light on every fifth second for one second and then it it switched off again.



1.1 Tip

sample(start, interval) returns true and triggers time events at time instants and rem(x, y) returns the integer remainder of x/y, such that div(x,y) * y + rem(x, y) = x.


1.2

1.2.1 LightSwitch


1.2.2 Simulation of LightSwitch




1.2.3 LightSwitchExtended


1.2.4 Simulation of LightSwitchExtended