Train Docs
Fall 2025
API

# SittingCar

o1.train.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.

## Parameters

numberOfRows

  the number of seat rows in the car

seatsPerRow

  the number of seats in each row

## Attributes

Graph
Supertypes
  trait TrainCar
  class Object
  trait Matchable
  class Any

## Members list

### 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.

## Parameters

numberOfRow

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

seat

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

## Attributes

def numberOfFreePlaces: Int

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

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

## Attributes

def numberOfPlaces: Int

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.

## Attributes

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.

## Parameters

numberOfRow

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

seat

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

## Attributes

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.

## Attributes

#### Inherited methods

def fullness: Double

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.

## Attributes

Inherited from:
  TrainCar

#### Concrete fields

val numberOfRows: Int
val seatsPerRow: Int