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

Class SleepingCar

source code

object --+
         |
        SleepingCar

The class SleepingCar represents the sleeping cars of a train in a train ticket reservation system. Each sleeping car is divided in cabins which have SleepingCar.BEDS_PER_CABIN places (beds) for passengers. The cabins are numbered from one upwards.

This implementation works in such a way that whenever anyone reserves any places in the car, at least one full cabin is reserved.

In this simple model, no data is stored about who has reserved which places (beds) in the cars. Cars will only know if places are reserved or not.

Instance Methods [hide private]
 
__init__(self, number_of_cabins)
Creates a new sleeping car with the given number of cabins.
source code
 
get_number_of_places(self)
Tells how many places (beds) this car has for passengers.
source code
 
get_degree_of_reservation(self)
Tells how many percent of the car's passenger places have been reserved.
source code
 
get_number_of_free_places(self)
Tells how many free (unreserved) places (beds) this car has for passengers.
source code
 
get_number_of_cabins(self)
Tells how many cabins there are in this car.
source code
 
get_number_of_free_beds_in_cabin(self, cabin_number)
Tells how many free (unreserved) places (beds) there are in the indicated cabin.
source code
 
cabin_is_empty(self, cabin_number)
Tells if the indicated cabin is empty.
source code
 
reserve_cabin(self, cabin_number)
Reserves all the places (beds) in one cabin.
source code
 
reserve_places(self, number_of_people)
Reserves places (beds) for a group.
source code
 
count_empty_cabins(self)
Returns the number of empty cabins in the car.
source code
 
find_empty_cabin(self)
Searches for the first empty cabin in the car.
source code

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

Class Variables [hide private]
  BEDS_PER_CABIN = 3
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, number_of_cabins)
(Constructor)

source code 

Creates a new sleeping car with the given number of cabins.

Parameters:
  • number_of_cabins - the number of cabins in the new car
Overrides: object.__init__

get_number_of_places(self)

source code 

Tells how many places (beds) this car has for passengers.

Returns:
the total number of passenger places in the car

get_degree_of_reservation(self)

source code 

Tells how many percent of the car's passenger places have been reserved.

Returns:
the degree of reservation for this car (percentage: 0.0 - 100.0).

get_number_of_free_places(self)

source code 

Tells how many free (unreserved) places (beds) this car has for passengers.

Returns:
the number of free passenger places in the car

get_number_of_cabins(self)

source code 

Tells how many cabins there are in this car.

Returns:
the number of cabins in the car

get_number_of_free_beds_in_cabin(self, cabin_number)

source code 

Tells how many free (unreserved) places (beds) there are in the indicated cabin.

Parameters:
  • cabin_number - a cabin number (>=1)
Returns:
the number of free places in the cabin

cabin_is_empty(self, cabin_number)

source code 

Tells if the indicated cabin is empty. That is, tells whether none of its beds have been reserved or not.

Parameters:
  • cabin_number - a cabin number (>=1)
Returns:
a boolean value indicating if the cabin is empty

reserve_cabin(self, cabin_number)

source code 

Reserves all the places (beds) in one cabin. If the cabin was not originally empty, this method does nothing but return False.

Parameters:
  • cabin_number - a cabin number (>=1)
Returns:
a boolean value indicating if the cabin was successfully reserved

reserve_places(self, number_of_people)

source code 

Reserves places (beds) for a group. For a sleeping car, a group reservation means that whole (originally empty) cabins are reserved so that all the members of the group fit in them. E.g. if the group size is 7, and each cabin has three beds, three cabins will be reserved.

The cabins to be reserved are selected simply so that the smallest possible empty cabin numbers are determined, and those cabins are reserved. The cabins need not be adjacent to each other.

If it is not possible to reserve suitable places for all members of the group, no places are reserved at all.

Parameters:
  • number_of_people - the size of the group for which places are to be reserved
Returns:
True if the group reservation was successful, False if not

count_empty_cabins(self)

source code 

Returns the number of empty cabins in the car.

Returns:
the number of empty cabins in the car

find_empty_cabin(self)

source code 

Searches for the first empty cabin in the car.

Returns:
the smallest empty cabin number in the car or a negative value, if no empty cabins can be found