The class Train
represents trains which consist of a number of passenger cars.
The cars are numbered from one upwards (starting from the head of the train).
A train object is mutable. New cars can be added to it with the addCar
method,
but initially a train has no cars. Trains have a maximum length (in cars) which
they must not exceed.
A train may contain cars of various types, that is, instances of any class that
mixes in the TrainCar
trait.
- Value parameters:
- description
a description of the train, e.g. "From Helsinki to Oulu, leaves at 8:13"
- Companion:
- object
Value members
Concrete methods
Adds the given car to the end of the train, if possible.
Adds the given car to the end of the train, if possible.
- Value parameters:
- car
the car to be added
- Returns:
true
if the car was added,false
if the length would have become excessive- See also:
Returns the car indicated by the given number, wrapped in an Option
.
Returns None
if the given number is too low or too high.
Returns the car indicated by the given number, wrapped in an Option
.
Returns None
if the given number is too low or too high.
- Value parameters:
- numberOfCar
the number of the car that should be returned (must be between 1 and the number of cars in the train or the result will be None)