class SleepingCar 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.
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.
- See also
- Alphabetic
- By Inheritance
- SleepingCar
- TrainCar
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new SleepingCar(numberOfCabins: Int)
- numberOfCabins
the number of cabins in this sleeping car
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def emptyCabinCount: Int
Returns the number of empty cabins in the car.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- 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.
- Definition Classes
- TrainCar
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def isEmptyCabin(cabinNumber: Int): Boolean
Determines if the indicated cabin is empty, that is, whether none of its beds have been reserved or not.
Determines if the indicated cabin is empty, that is, whether none of its beds have been reserved or not.
- cabinNumber
a cabin number (>=1 and no bigger than the number of cabins)
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- val numberOfCabins: Int
- def numberOfFreeBedsInCabin(cabinNumber: Int): Int
Returns the number of free (unreserved) places (beds) there are in the given cabin.
Returns the number of free (unreserved) places (beds) there are in the given cabin.
- cabinNumber
a cabin number (>=1 and no bigger than the number of cabins)
- def numberOfFreePlaces: Int
Returns the number of free, unreserved places (beds) in this car.
Returns the number of free, unreserved places (beds) in this car.
- Definition Classes
- SleepingCar → TrainCar
- def numberOfPlaces: Int
Returns the number of places (beds) this car has for passengers.
Returns the number of places (beds) this car has for passengers. This is a positive number.
- Definition Classes
- SleepingCar → TrainCar
- def reserveCabin(cabinNumber: Int): Boolean
Reserves all the places (beds) in one cabin.
Reserves all the places (beds) in one cabin. Returns a boolean value indicating whether the reservation was successful. If the cabin was not originally empty, this method does nothing but return
false
.- cabinNumber
a cabin number (>=1 and no bigger than the number of cabins)
- def reservePlaces(numberOfPeople: Int): Boolean
Reserves places (beds) for a group of people whose size is indicated by the parameter.
Reserves places (beds) for a group of people whose size is indicated by the parameter. For a sleeping car, a group reservation means that a number of entire empty cabins is reserved so that all the members of the group fit in them. For instance, if the group size is seven, and each cabin has three beds, three whole cabins will be reserved.
The cabins to be reserved are selected simply so that the smallest available numbers of empty cabins are determined, and those cabins are reserved. The cabins need not be adjacent to each other, but must all be in this car.
If it is not possible to reserve suitable cabins for all members of the group, no places are reserved at all. The return value of this method indicates whether the places were reserved or not.
- Definition Classes
- SleepingCar → TrainCar
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString: String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
- Deprecated
(Since version ) see corresponding Javadoc for more information.