package Domäne; import java.util.Arrays; import tpe.exceptions.roboter.Robot; import tpe.exceptions.roboter.exceptions.RobotException; import tpe.exceptions.roboter.exceptions.RobotIllegalStateException; import tpe.exceptions.roboter.exceptions.RobotMagicValueException; public class R2D2 extends Roboter { private int id; //private static int idZähler = 0; private RobotType robotType; //RobotException fehler; public R2D2(String name, int id) { super(name); this.robotType = RobotType.R2D2; this.id = id; //idZähler++; } @Override public int[] think(int[] zahlen) throws RobotException { if (isPowerOn() == true) { for (int zahl : zahlen) { if (zahl == 42) { fehler = new RobotMagicValueException("Fehler! Zahl 42 im Array!", this.name); throw fehler; } } for (int i = 0; i < zahlen.length - 1; i++) { for (int k = i + 1; k < zahlen.length; k++) { if (zahlen[i] > zahlen[k]) { int größer = zahlen[i]; zahlen[i] = zahlen[k]; zahlen[k] = größer; } } } return zahlen; } else fehler = new RobotIllegalStateException("Roboter ausgeschaltet! Bitte einschalten.", this.name); throw fehler; } @Override public int getId() { return id; } public RobotType getRobotType () { return this.robotType; } }