The class Lane

We let a lane consist of a number of positions, that may either contain a vehicle or be empty (None).

Use a list of fixed length. Vehicles enter on one end (at the highest index) and leaves out from the other end (index 0).

bild

Simplication of reality: All vehicles occupy the same amount of space.

What happens in the lane during a time step?

bild

bild

bild

bild

bild

Note that a vehicle is being moved at most one position each time step.

Simplication of reality: A vehicle either is standing still or moving eactly one position each time step.

What happens at the ends of Lane?

The class Lane has no knowledge of what is in front or behind it. It is "someone else" that makes shure that vehicles arrive to the lane and leaves the lane.

Lane needs to make available a method to extract vehicles from the first position and return the vehicle there.

bild

There also needs to be a method that places a vehicle in the last position:

bild

If one adds a vehicle at the last position and it was not unoccupied, the vehicle that was there will be lost:

bild

Therefore, there needs to exist a method that gives information on if the last position is unoccupied or not.

We arrive at the following class diagram:

bild

Back

Valid CSS!