o1.train
Type members
Classlikes
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.
- Value parameters:
- numberOfRows
the number of seat rows in the car
- seatsPerRow
the number of seats in each row
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.
- Value parameters:
- numberOfCabins
the number of cabins in this sleeping car
- See also:
- Companion:
- object
This companion object of the SleepingCar
class merely provides a named constant that the class uses.
This companion object of the SleepingCar
class merely provides a named constant that the class uses.
- See also:
the class SleepingCar
- Companion:
- class
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
mixes in the TrainCar
trait.
- Value parameters:
- description
a description of the train, e.g. "From Helsinki to Oulu, leaves at 8:13"
- Companion:
- object
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.