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

Class SittingCar

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.
float
get_degree_of_reservation(self)
Tells how many percent of the car's passenger places have been reserved.
int
get_number_of_rows(self)
Returns the number of seat rows in the car.
int
get_row_width(self)
Returns the number of seats per row in the car.
int
get_number_of_places(self)
Tells how many places (seats) this car has for passengers.
int
get_number_of_free_places(self)
Tells how many free (unreserved) places (seats) this car has for passengers.
boolean
is_seat_reserved(self, number_of_row, seat)
Tells if the indicated seat is reserved or not.
boolean
reserve_place(self, number_of_row, seat)
Reserves the indicated seat, if possible.
boolean
reserve_places(self, number_of_people)
Reserves places (seats) for a group.
int
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.
 
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.

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)

 

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 @type : int
  • row_width - number of seats per row @type : int
Overrides: object.__init__

get_degree_of_reservation(self)

 

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

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

get_number_of_rows(self)

 

Returns the number of seat rows in the car.

Returns: int
the number of seat rows

get_row_width(self)

 

Returns the number of seats per row in the car.

Returns: int
the number of seats per row

get_number_of_places(self)

 

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

Returns: int
the total number of passenger places in the car

get_number_of_free_places(self)

 

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

Returns: int
the number of free passenger places in the car

is_seat_reserved(self, number_of_row, seat)

 

Tells if the indicated seat is reserved or not.

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

reserve_place(self, number_of_row, seat)

 

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

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

reserve_places(self, number_of_people)

 

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 @type : int
Returns: boolean
True if the group reservation was successful, False if not

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.

Parameters:
  • row_index - the index (>=0) of a row @type : int
  • seat_index - the index (>=0) of a place @type : int
  • number_of_seats - the hoped-for number of adjacent seats @type : int
Returns: int
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)

 

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 @type : int
  • seat_index - the index (>=0) of a place @type : int
  • number_of_seats - the number of seats to reserve starting with the one indicated by the other parameters @type : int