letzte Änderungen

main
Lukas Berens 2023-01-08 09:54:17 +01:00
parent 40c35b2ea8
commit 3d43125f32
3 changed files with 30 additions and 31 deletions

View File

@ -1,8 +1,9 @@
package tpe.exceptions.roboter; package tpe.exceptions.roboter;
import tpe.exceptions.RobotException; import tpe.exceptions.RobotException;
import tpe.exceptions.RobotIllegalStateException;
public class Nexus6 implements RobotControl, RobotInstructions { public class Nexus6 extends Robots {
private RobotType robotType; private RobotType robotType;
private static int id=19281982; private static int id=19281982;
private static String name="Pris"; private static String name="Pris";
@ -11,7 +12,7 @@ public class Nexus6 implements RobotControl, RobotInstructions {
private Nexus6(int id, String name, boolean powerSwitch) { private Nexus6(int id, String name, boolean powerSwitch) {
super(); super(name);
robotType= RobotType.NEXUS6; robotType= RobotType.NEXUS6;
} }
@ -19,15 +20,15 @@ public class Nexus6 implements RobotControl, RobotInstructions {
return instance; return instance;
} }
@Override @Override
public String speak(int[] zahlen) { public String speak(int[] zahlen) throws RobotException {
// TODO Auto-generated method stub throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName());
return null;
} }
@Override @Override
public int[] think(int[] zahlen) { public int[] think(int[] zahlen) throws RobotException {
// TODO Auto-generated method stub throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName());
return null;
} }
public int getId() { public int getId() {
@ -35,26 +36,12 @@ public class Nexus6 implements RobotControl, RobotInstructions {
return id; return id;
} }
@Override
public String getName() {
return name;
}
@Override
public void triggerPowerSwitch() {
powerSwitch=false;
}
@Override
public boolean isPowerOn() {
return powerSwitch;
}
@Override @Override
public RobotException getLastException() { public RobotException getLastException() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
public RobotType getRobotType () {
return this.robotType;
}
} }

View File

@ -20,7 +20,10 @@ public class R2D2 extends Robots {
this.name = name; this.name = name;
robotType= RobotType.R2D2; robotType= RobotType.R2D2;
} }
@Override
public int getId() {
return id;
}
@Override @Override
public String speak(int[] zahlen) throws RobotException { public String speak(int[] zahlen) throws RobotException {

View File

@ -10,22 +10,31 @@ public class RobotFactory {
public int constructRobot(RobotType robotType, String name) { public int constructRobot(RobotType robotType, String name) {
Robots robot; Robots robot;
if(RobotType.R2D2==robotType) { if(RobotType.R2D2==robotType) {
robot=new R2D2(name, checkID(0,9999)); robot=new R2D2(name, createIDR2D2(0,9999));
robotStock.put(robot.getId(), robot); robotStock.put(robot.getId(), robot);
return robot.getId(); return robot.getId();
}else if(RobotType.C3PO==robotType) { }else if(RobotType.C3PO==robotType) {
robot=new C3PO(name, checkID()); robot=new C3PO(name, createIDC3PO(10000, 19999));
robotStock.put(robot.getId(), robot); robotStock.put(robot.getId(), robot);
return robot.getId(); return robot.getId();
} }
} }
private int checkID(int minValue, int maxValue) { private int createIDR2D2(int minValue, int maxValue) {
int randomID = (int) (Math.random()*(maxValue - minValue)) + minValue; int randomID = (int) (Math.random()*(maxValue)) ;
if(robotStock.containsKey(randomID)) if(robotStock.containsKey(randomID))
{ {
checkID(minValue,maxValue); createIDR2D2(minValue,maxValue);
}
return randomID;
}
private int createIDC3PO(int minValue, int maxValue) {
int randomID = (int) (Math.random()*(maxValue))+minValue ;
if(robotStock.containsKey(randomID))
{
createIDC3PO(minValue,maxValue);
} }
return randomID; return randomID;
} }