From 324231ef071774ee5871a2b501239773d6fd925b Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Sat, 29 Feb 2020 11:11:00 +0100 Subject: [PATCH] Make sure rolling stock has at least one coupling --- src/edu/kit/informatik/model/RollingStock.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/edu/kit/informatik/model/RollingStock.java b/src/edu/kit/informatik/model/RollingStock.java index 6d08e3b..783448e 100644 --- a/src/edu/kit/informatik/model/RollingStock.java +++ b/src/edu/kit/informatik/model/RollingStock.java @@ -27,13 +27,16 @@ public abstract class RollingStock { * @param length length of this rolling stock * @param couplingFront whether this rolling stock should have a front coupling * @param couplingBack whether this rolling stock should have a back coupling - * @throws InvalidInputException on invalid user input (zero-sized coach) + * @throws InvalidInputException on invalid user input (e.g. zero-sized coach) */ protected RollingStock(final int length, final boolean couplingFront, final boolean couplingBack) throws InvalidInputException { if (length < 1) { throw new InvalidInputException("rolling stock length has to be positive"); } + if (!couplingFront && !couplingBack) { + throw new InvalidInputException("rolling stocks needs at least one coupling"); + } this.length = length; this.couplingFront = couplingFront; this.couplingBack = couplingBack;