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'.
When created, all the seats in a sitting car are unreserved. This changes as reservations are made.
In this simple implementation, no data is stored about who has reserved which seat.
Reserves the indicated seat, if possible. The reservation is unsuccessful if the seat was already reserved. In the latter case, the method returns false; it returns true otherwise.
Reserves the indicated seat, if possible. The reservation is unsuccessful if the seat was already reserved. In the latter case, the method returns false; it returns true otherwise.
Parameters
numberOfRow
a row number (valid number that is >=1)
seat
a seat identifier (valid small letter, from 'a' onwards)
Reserves places (seats) for a group of people whose size is indicated by the parameter. For a sitting car, a group reservation means that the whole group must get adjacent seats in the same row.
Reserves places (seats) for a group of people whose size is indicated by the parameter. For a sitting car, a group reservation means that the whole group must get adjacent seats in 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 seats for all members of the group, no places are reserved at all. The return value of this method indicates whether the seats were reserved or not.