M250 Object-oriented Java programming
PART A Open the LevelCrossingController and Light classes before proceeding further and familiarise yourself with their contents. Note the delay() method in LevelCrossingController. The LevelCrossingController class has four instance variables: topLeft, topRightand bottom reference instances of Light at the top left, top right, and bottom of the warning system display trainComingis a boolean instance variable which will be used when changing the state of the warning lights. In the LevelCrossingController class write a public instance method with the signature colourLight(Light, OUColour), which returns no value. This method should set the colour of the specified light to the specified colour if it is one of OUColour.RED, OUColour.GREEN, OUColour.ORANGE or OUColour.BLACK. Otherwise, the colour should be unchanged. You should make use of a method in Light.
PART B - INFORMATION In the UK, the cycle of colours for level crossing warning lights is bottom orange, then as the barrier lowers… the left and right top lights flash red, then all lights turn off as the barrier rises. The initial state will be all lights off. An integer instance variable state is required which will take the values 0,1,2 or 3. The pattern of lights corresponding to the value of state is: state bottom top left top right trainComing 0 black black black false 1 orange black black true 2 black red black true 3 black black red true As the lights operate, the state will typically go: 0, 1, 2, 3, 2, 3, 2, 3………0 The number of red flashes depends on the length of the approaching train, but we will allow a user to set this value. PART B (i) Add the instance variable state, suitably commented, to your LevelCrossingController class.
PART B (ii) Now write a public constructor for the class LevelCrossingController that takes three Light references as arguments, sets the given instance variables topLeft, topRight and bottom to reference these arguments (in that order), sets their positions using the provided private method setPositions(), sets the value of state to 0 and sets the value of trainComing to false. It is a good idea to test your constructor at this point PART C (i) Write a public instance method changeState() which takes no argument and returns no value. If trainComing is true, then it should change the value of state as follow