Train

o1.train.Train
See theTrain companion object
class Train(val description: String)

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 extends TrainCar.

Parameters

description

a description of the train, e.g. "From Helsinki to Oulu, leaves at 8:13"

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def addCar(car: TrainCar): Boolean

Adds the given car to the end of the train, if possible.

Adds the given car to the end of the train, if possible.

Parameters

car

the car to be added

Attributes

Returns

true if the car was added, false if the length would have become excessive

See also
def car(numberOfCar: Int): Option[TrainCar]

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.

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)

Attributes

def length: Int

Returns the number of (passenger) cars there are in this train.

Returns the number of (passenger) cars there are in this train.

Attributes

Concrete fields