Package train :: Module train :: Class Train
[hide private]
[frames] | no frames]

Class Train

source code

object --+
         |
        Train

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). Each train has a maximum length (in cars) which it must not exceed. A train may contain cars of various types.

Instance Methods [hide private]
 
__init__(self, description)
Creates a new train with the given description and no passenger cars in it.
source code
 
add_car(self, car)
Adds a new car to the end of the train, if possible.
source code
 
get_car(self, number_of_car)
Returns the car indicated by the given car number.
source code
 
get_size(self)
Tells how many (passenger) cars there are in this train.
source code
 
get_description(self)
Returns the description of the train.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  MAXIMUM_LENGTH = 30
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, description)
(Constructor)

source code 

Creates a new train with the given description and no passenger cars in it.

Parameters:
  • description - a description of the train, e.g. "From Helsinki to Oulu, May 2nd, leaves at 8:13"
Overrides: object.__init__

add_car(self, car)

source code 

Adds a new car to the end of the train, if possible.

Parameters:
  • car - the car to be added to the train
Returns:
a boolean value indicating if the car was successfully added (or if the maximum length would be exceeded)

get_car(self, number_of_car)

source code 

Returns the car indicated by the given car number.

Parameters:
  • number_of_car - the number of the car (>=1) which should be returned
Returns:
the car indicated by the parameter or None if no such car exists

get_size(self)

source code 

Tells how many (passenger) cars there are in this train.

Returns:
the size of the train, in cars

get_description(self)

source code 

Returns the description of the train.

Returns:
train description