kit-programmieren-ws1920-fi.../src/edu/kit/informatik/model/TrainSet.java
2020-02-17 11:00:15 +01:00

80 lines
2.1 KiB
Java

package edu.kit.informatik.model;
/**
* Train set.
*
* @author Arne Keller
* @version 1.0
*/
public class TrainSet extends RollingStock {
/**
* ASCII art representation of a train set.
*/
private static final String[] TRAIN_SET_TEXT = new String[] {
" ++ ",
" || ",
"_________||_________",
"| ___ ___ ___ ___ |",
"| |_| |_| |_| |_| |",
"|__________________|",
"|__________________|",
" (O) (O) "
};
/**
* Series (class) of this train set.
*/
private String series;
/**
* Name of this train set. TODO: create NamedRollingStock class
*/
private String name;
/**
* Construct a new train set.
* @param series series/class of train set
* @param name name of train set
* @param length length of train set
* @param couplingFront whether the train set should have a front coupling
* @param couplingBack whether the train set should have a back coupling
*/
public TrainSet(final String series, final String name, final int length,
final boolean couplingFront, final boolean couplingBack) {
this.name = name;
this.series = series;
super.length = length;
super.couplingFront = couplingFront;
super.couplingBack = couplingBack;
}
@Override
public String getIdentifier() {
return String.format("%s-%s", series, name);
}
@Override
public String toString() {
return String.format("%s %s %d %b %b", series, name, length, couplingFront, couplingBack);
}
@Override
public boolean canCoupleFrontTo(RollingStock rollingStock) {
return hasCouplingFront() && rollingStock.hasCouplingBack() && rollingStock.canCoupleToTrainSetSeries(series);
}
@Override
public boolean canCoupleToTrainSetSeries(String series) {
return this.series.equals(series);
}
@Override
public String[] textRepresentation() {
return TRAIN_SET_TEXT;
}
@Override
public String description() {
return "train-set";
}
}