Train Docs
Fall 2025
API

# o1.train

package o1.train

## Members list

### Type members

#### Classlikes

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

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

Supertypes
  trait TrainCar
  class Object
  trait Matchable
  class Any

class SleepingCar(val `numberOfCabins`: Int) extends TrainCar

The class `SleepingCar` represents sleeping cars in a train ticket reservation system. Each sleeping car is divided in equal-sized cabins which have a set number of places (beds) for passengers. The cabins are numbered from one upwards.

The class `SleepingCar` represents sleeping cars in a train ticket reservation system. Each sleeping car is divided in equal-sized cabins which have a set number of places (beds) for passengers. The cabins are numbered from one upwards.

When created, all the cabins in a sleeping car are unreserved. This changes as reservations are made.

This implementation is intended to work in such a way that whenever anyone reserves any places in the car, at least one full cabin is reserved. Multiple reservations can never share a cabin.

In this simple implementation, no data is stored about who has reserved which cabins.

## Parameters

numberOfCabins

  the number of cabins in this sleeping car

## Attributes

See also

  SleepingCar.BedsPerCabin

Companion
  object
Supertypes
  trait TrainCar
  class Object
  trait Matchable
  class Any

object SleepingCar

This `SleepingCar` companion object merely provides a named constant that the class uses.

This `SleepingCar` companion object merely provides a named constant that the class uses.

## Attributes

See also

  the SleepingCar class

Companion
  class
Supertypes
  class Object
  trait Matchable
  class Any
Self type
  SleepingCar.type

class Train(val `description`: String)

The class `Train` represents trains which consist of a number of passenger cars. The cars are numbered from one upwards (starting from the head of the train).

The class `Train` represents trains which consist of a number of passenger cars. The cars are numbered from one upwards (starting from the head of the train).

A train object is mutable. New cars can be added to it with the `addCar` method, but initially a train has no cars. Trains have a maximum length (in cars) which they must not exceed.

A train may contain cars of various types, that is, instances of any class that extends `TrainCar`.

## Parameters

description

  a description of the train, e.g. "From Helsinki to Oulu, leaves at 8:13"

## Attributes

Companion
  object
Supertypes
  class Object
  trait Matchable
  class Any

object Train

This companion object of the `Train` class merely provides a named constant that the class uses.

This companion object of the `Train` class merely provides a named constant that the class uses.

## Attributes

See also

  the class Train

Companion
  class
Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Train.type

trait TrainCar

This trait represents the passenger cars of a train in a train ticket reservation system. It describes the common operations of all passenger car types. Different classes representing different kinds of train cars will have different implementations for these operations.

This trait represents the passenger cars of a train in a train ticket reservation system. It describes the common operations of all passenger car types. Different classes representing different kinds of train cars will have different implementations for these operations.

In this simple implementation, no data is stored about who has reserved which places (seats, beds, or the like) in the cars. A car object only keeps track of whether a place is reserved or not.

A train car’s state is mutable; it changes as reservations are made.

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Known subtypes
  class SittingCar
  class SleepingCar