kit-programmieren-ws1920-fi.../src/edu/kit/informatik/model/TrainSet.java

73 lines
1.9 KiB
Java
Raw Normal View History

2020-02-16 14:01:33 +00:00
package edu.kit.informatik.model;
2020-02-15 14:17:23 +00:00
2020-02-15 15:38:54 +00:00
/**
* Train set.
*
* @author Arne Keller
* @version 1.0
*/
2020-02-15 14:17:23 +00:00
public class TrainSet extends RollingStock {
2020-02-17 10:00:15 +00:00
/**
* ASCII art representation of a train set.
*/
2020-02-15 15:38:54 +00:00
private static final String[] TRAIN_SET_TEXT = new String[] {
" ++ ",
" || ",
"_________||_________",
"| ___ ___ ___ ___ |",
"| |_| |_| |_| |_| |",
"|__________________|",
"|__________________|",
" (O) (O) "
};
2020-02-17 10:00:15 +00:00
/**
* Series (class) of this train set.
*/
2020-02-15 14:17:23 +00:00
private String series;
2020-02-17 10:00:15 +00:00
/**
* Name of this train set. TODO: create NamedRollingStock class
*/
2020-02-15 14:17:23 +00:00
private String name;
2020-02-15 15:38:54 +00:00
/**
* 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) {
2020-02-17 12:59:42 +00:00
super(length, couplingFront, couplingBack);
2020-02-15 14:17:23 +00:00
this.name = name;
this.series = series;
}
@Override
public String getIdentifier() {
return String.format("%s-%s", series, name);
}
@Override
public String toString() {
2020-02-17 12:59:42 +00:00
return String.format("%s %s %d %b %b", series, name, getLength(), hasCouplingFront(), hasCouplingBack());
2020-02-15 14:17:23 +00:00
}
@Override
public boolean canCoupleTo(RollingStock rollingStock) {
return rollingStock.getClass().equals(this.getClass()) && ((TrainSet) rollingStock).series.equals(this.series);
2020-02-15 14:17:23 +00:00
}
@Override
public String[] textRepresentation() {
return TRAIN_SET_TEXT;
}
@Override
public String description() {
return "train-set";
}
}