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

Class SittingCar

source code

object --+
         |
        SittingCar

The class SittingCar represents passenger cars with seats in a train ticket reservation system. Each sitting car has rows of seats, which are numbered starting from one upwards. Each row has a number of seats, identified by letters starting from 'a'.

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

Instance Methods [hide private]
 
__init__(self, number_of_rows, row_width)
Creates a new sitting car with the given number of seat rows, and the given number of seats per row.
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_rows(self)
Returns the number of seat rows in the car.
source code
 
get_row_width(self)
Returns the number of seats per row in the car.
source code
 
get_number_of_places(self)
Tells how many places (seats) this car has for passengers.
source code
 
get_number_of_free_places(self)
Tells how many free (unreserved) places (seats) this car has for passengers.
source code
 
is_seat_reserved(self, number_of_row, seat)
Tells if the indicated seat is reserved or not.
source code
 
reserve_place(self, number_of_row, seat)
Reserves the indicated seat, if possible.
source code
 
reserve_places(self, number_of_people)
Reserves places (seats) for a group.
source code
 
find_adjacents(self, row_index, seat_index, number_of_seats)
Tells if the given number of adjacent seats are free at the given location in the car.
source code
 
reserve_adjacents(self, row_index, seat_index, number_of_seats)
Reserves the given number of adjacent seats starting at the given location in the car.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, number_of_rows, row_width)
(Constructor)

source code 

Creates a new sitting car with the given number of seat rows, and the given number of seats per row.

Parameters:
  • number_of_rows - number of seat rows
  • row_width - number of seats per row
Overrides: object.__init__

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_rows(self)

source code 

Returns the number of seat rows in the car.

Returns:
the number of seat rows

get_row_width(self)

source code 

Returns the number of seats per row in the car.

Returns:
the number of seats per row

get_number_of_places(self)

source code 

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

Returns:
the total number of passenger places in the car

get_number_of_free_places(self)

source code 

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

Returns:
the number of free passenger places in the car

is_seat_reserved(self, number_of_row, seat)

source code 

Tells if the indicated seat is reserved or not.

Parameters:
  • number_of_row - row number (>=1)
  • seat - seat identifier (small letter, from 'a' onwards)
Returns:
a boolean value indicating if the seat is reserved

reserve_place(self, number_of_row, seat)

source code 

Reserves the indicated seat, if possible. The reservation is unsuccessful if the seat was already reserved.

Parameters:
  • number_of_row - row number (>=1)
  • seat - seat identifier (small letter, from 'a' onwards)
Returns:
a boolean value indicating if the seat was successfully reserved

reserve_places(self, number_of_people)

source code 

Reserves places (seats) for a group. For a sitting car, a group reservation means that the whole group must get adjacent seats from the same row.

Where it would be possible to make the reservation in many different ways, the smallest possible row number and first (alphabetically) possible seat identifiers are selected.

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

find_adjacents(self, row_index, seat_index, number_of_seats)

source code 

Tells if the given number of adjacent seats are free at the given location in the car.

Parameters:
  • row_index - the index (>=0) of a row
  • seat_index - the index (>=0) of a place
  • number_of_seats - the hoped-for number of adjacent seats
Returns:
the given number of seats, if a sequence of adjacent free seats was found at the given location, or a smaller number of seats if so many were not found

reserve_adjacents(self, row_index, seat_index, number_of_seats)

source code 

Reserves the given number of adjacent seats starting at the given location in the car. Assumes that those seats really are free to begin with.

Parameters:
  • row_index - the index (>=0) of a row
  • seat_index - the index (>=0) of a place
  • number_of_seats - the number of seats to reserve starting with the one indicated by the other parameters