Singleton Nexus 6 implementiert

Singleton
cedri 2023-01-08 11:26:07 +01:00
parent 8e874ca7b1
commit 81ee821d87
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;
public enum RobotType {
C3PO, R2D2;
C3PO, R2D2, NEXUS6;
}

View File

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