SittingCar

class SittingCar(val numberOfRows: Int, val seatsPerRow: Int) extends TrainCar

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.

Value parameters:
numberOfRows

the number of seat rows in the car

seatsPerRow

the number of seats in each row

trait TrainCar
class Object
trait Matchable
class Any

Value members

Concrete methods

def isReservedSeat(numberOfRow: Int, seat: Char): Boolean

Returns a Boolean value indicating whether the indicated seat is reserved or not.

Returns a Boolean value indicating whether the indicated seat is reserved or not.

Value parameters:
numberOfRow

a row number (valid number that is >=1)

seat

a seat identifier (valid small letter, from 'a' onwards)

Returns the number of free, unreserved places (seats) in this car.

Returns the number of free, unreserved places (seats) in this car.

Returns the number of places (seats) this car has for passengers. This is a positive number.

Returns the number of places (seats) this car has for passengers. This is a positive number.

def reservePlace(numberOfRow: Int, seat: Char): Boolean

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.

Value parameters:
numberOfRow

a row number (valid number that is >=1)

seat

a seat identifier (valid small letter, from 'a' onwards)

def reservePlaces(numberOfPeople: Int): Boolean

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.

Inherited methods

Returns a figure between 0 and 100 that indicates how many percent of the car’s passenger places have been reserved.

Returns a figure between 0 and 100 that indicates how many percent of the car’s passenger places have been reserved.

Inherited from:
TrainCar

Concrete fields