RoboterFabrik/Roboter/tpe/exceptions/roboter/C3PO.java

57 lines
1.1 KiB
Java
Raw Normal View History

2022-12-27 11:09:41 +01:00
package tpe.exceptions.roboter;
2023-01-08 15:28:19 +01:00
import tpe.exceptions.RobotIllegalStateException;
import tpe.exceptions.RobotMagicValueException;
2022-12-27 11:09:41 +01:00
2023-01-09 18:29:56 +01:00
public class C3PO extends Robots {
2023-01-08 15:28:19 +01:00
RobotType robotType;
2023-01-09 18:29:56 +01:00
2023-01-08 15:28:19 +01:00
private int id;
2023-01-09 18:29:56 +01:00
2023-01-08 15:28:19 +01:00
StringBuilder sb = new StringBuilder();
2022-12-27 11:09:41 +01:00
2023-01-08 15:28:19 +01:00
public C3PO(String name, int id) {
super(name);
this.id = id;
this.name = name;
robotType = RobotType.C3PO;
2022-12-27 11:09:41 +01:00
2023-01-09 18:29:56 +01:00
}
2022-12-27 11:09:41 +01:00
2023-01-09 18:29:56 +01:00
@Override
2023-01-08 15:28:19 +01:00
public int[] think(int[] zahlen) throws RobotIllegalStateException, RobotMagicValueException {
2023-01-09 18:29:56 +01:00
if (!isPowerOn()) {
2023-01-08 15:28:19 +01:00
throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName());
2023-01-09 18:29:56 +01:00
} else if (checkRobotMagicValueException(zahlen) == true) {
throw new RobotMagicValueException("Zahl 42 kann nicht verarbeitet werden!", this.getName());
} else {
2023-01-08 15:28:19 +01:00
int z;
2023-01-09 18:29:56 +01:00
2023-01-08 15:28:19 +01:00
for (int i = 1; i < zahlen.length; i++) {
z = zahlen[i];
int k = i;
2023-01-09 18:29:56 +01:00
2023-01-08 15:28:19 +01:00
while (k > 0 && zahlen[k - 1] < z) {
zahlen[k] = zahlen[k - 1];
k--;
}
zahlen[k] = z;
}
}
2023-01-09 18:29:56 +01:00
2023-01-08 15:28:19 +01:00
return zahlen;
2023-01-09 18:29:56 +01:00
}
2022-12-27 11:09:41 +01:00
2023-01-08 15:28:19 +01:00
public RobotType getRobotType() {
return this.robotType;
2022-12-27 11:09:41 +01:00
}
@Override
2023-01-08 15:28:19 +01:00
public int getId() {
2023-01-09 18:29:56 +01:00
2023-01-08 15:28:19 +01:00
return id;
2022-12-27 11:09:41 +01:00
}
}