56 lines
1.2 KiB
Java
56 lines
1.2 KiB
Java
package Domäne;
|
|
|
|
import tpe.exceptions.roboter.exceptions.RobotException;
|
|
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
|
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
|
|
|
public class C3PO extends Roboter {
|
|
String name;
|
|
int id;
|
|
static int idZähler = 10000;
|
|
RobotType robotType;
|
|
RobotException fehler;
|
|
|
|
C3PO(String name) {
|
|
super(name);
|
|
this.robotType = robotType.C3PO;
|
|
this.id = idZähler;
|
|
idZähler++;
|
|
}
|
|
|
|
@Override
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
@Override
|
|
public int[] think(int[] zahlen) throws RobotException {
|
|
int remember;
|
|
|
|
if (isPowerOn() == true) {
|
|
for (int zahl : zahlen) {
|
|
if (zahl == 42) {
|
|
fehler = new RobotMagicValueException("Fehler! Zahl 42 im Array!");
|
|
throw fehler;
|
|
}
|
|
}
|
|
|
|
for (int i = 1; i < zahlen.length; i++) {
|
|
remember = zahlen[i];
|
|
int k = i;
|
|
|
|
while (k > 0 && zahlen[k - 1] < remember) {
|
|
zahlen[k] = zahlen[k - 1];
|
|
k--;
|
|
}
|
|
zahlen[k] = remember;
|
|
}
|
|
return zahlen;
|
|
} else
|
|
fehler = new RobotIllegalStateException("Roboter ausgeschaltet! Bitte einschalten.");
|
|
throw fehler;
|
|
|
|
}
|
|
|
|
}
|