Merge remote-tracking branch 'origin/Singleton' into main

C3POTest
cedri 2023-01-08 11:28:13 +01:00
commit b80e9ddc0f
3 changed files with 45 additions and 3 deletions

View File

@ -0,0 +1,39 @@
package domain;
import exceptions.RobotException;
import exceptions.RobotIllegalStateException;
import roboterSystem.Robot;
public class Nexus6 extends Robotermodell implements Robot {
private static final Nexus6 NEXUS6 = new Nexus6();
private Nexus6() {
setName("Pris");
setiD(19281982);
power = false;
}
public static Nexus6 getInstance() {
return NEXUS6;
}
@Override
public void triggerPowerSwitch() {
//bleibt ausgeschaltet
}
@Override
public int[] think(int[] zahlen) throws RobotException {
try {
if (this.isPowerOn() == false) {
throw new RobotIllegalStateException();
}
} catch (RobotIllegalStateException rise) {
letzteException = rise;
rise.printStackTrace();
}
return null;
}
}

View File

@ -1,5 +1,5 @@
package domain; package domain;
public enum RobotType { public enum RobotType {
C3PO, R2D2; C3PO, R2D2, NEXUS6;
} }

View File

@ -10,7 +10,7 @@ import roboterSystem.Robot;
public abstract class Robotermodell implements Robot { public abstract class Robotermodell implements Robot {
private int iD; private int iD;
private String name; private String name;
private boolean power = true; protected boolean power = true;
protected RobotException letzteException; protected RobotException letzteException;
public void setName(String name) { public void setName(String name) {
@ -69,8 +69,11 @@ public abstract class Robotermodell implements Robot {
if (this instanceof C3PO) { if (this instanceof C3PO) {
hilfszeichen = ";"; hilfszeichen = ";";
} else { } else if (this instanceof R2D2){
hilfszeichen = ","; hilfszeichen = ",";
} else {
//wird beim Nexus6 geworfen
throw new RobotIllegalStateException();
} }
Arrays.stream(zahlen) Arrays.stream(zahlen)