diff --git a/Roboter/tpe/exceptions/roboter/Nexus6.java b/Roboter/tpe/exceptions/roboter/Nexus6.java index 8d3b462..5fce3e6 100644 --- a/Roboter/tpe/exceptions/roboter/Nexus6.java +++ b/Roboter/tpe/exceptions/roboter/Nexus6.java @@ -1,8 +1,9 @@ package tpe.exceptions.roboter; import tpe.exceptions.RobotException; +import tpe.exceptions.RobotIllegalStateException; -public class Nexus6 implements RobotControl, RobotInstructions { +public class Nexus6 extends Robots { private RobotType robotType; private static int id=19281982; private static String name="Pris"; @@ -11,7 +12,7 @@ public class Nexus6 implements RobotControl, RobotInstructions { private Nexus6(int id, String name, boolean powerSwitch) { - super(); + super(name); robotType= RobotType.NEXUS6; } @@ -19,15 +20,15 @@ public class Nexus6 implements RobotControl, RobotInstructions { return instance; } @Override - public String speak(int[] zahlen) { - // TODO Auto-generated method stub - return null; + public String speak(int[] zahlen) throws RobotException { + throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName()); + } @Override - public int[] think(int[] zahlen) { - // TODO Auto-generated method stub - return null; + public int[] think(int[] zahlen) throws RobotException { + throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName()); + } public int getId() { @@ -35,26 +36,12 @@ public class Nexus6 implements RobotControl, RobotInstructions { return id; } - @Override - public String getName() { - return name; - } - - @Override - public void triggerPowerSwitch() { - powerSwitch=false; - } - - @Override - public boolean isPowerOn() { - return powerSwitch; - } - - @Override public RobotException getLastException() { // TODO Auto-generated method stub return null; } - + public RobotType getRobotType () { + return this.robotType; + } } diff --git a/Roboter/tpe/exceptions/roboter/R2D2.java b/Roboter/tpe/exceptions/roboter/R2D2.java index 118f5ed..9eaec30 100644 --- a/Roboter/tpe/exceptions/roboter/R2D2.java +++ b/Roboter/tpe/exceptions/roboter/R2D2.java @@ -20,7 +20,10 @@ public class R2D2 extends Robots { this.name = name; robotType= RobotType.R2D2; } - + @Override + public int getId() { + return id; + } @Override public String speak(int[] zahlen) throws RobotException { diff --git a/Roboter/tpe/exceptions/roboter/RobotFactory.java b/Roboter/tpe/exceptions/roboter/RobotFactory.java index 834a29c..054e6ea 100644 --- a/Roboter/tpe/exceptions/roboter/RobotFactory.java +++ b/Roboter/tpe/exceptions/roboter/RobotFactory.java @@ -10,22 +10,31 @@ public class RobotFactory { public int constructRobot(RobotType robotType, String name) { Robots robot; if(RobotType.R2D2==robotType) { - robot=new R2D2(name, checkID(0,9999)); + robot=new R2D2(name, createIDR2D2(0,9999)); robotStock.put(robot.getId(), robot); return robot.getId(); }else if(RobotType.C3PO==robotType) { - robot=new C3PO(name, checkID()); + robot=new C3PO(name, createIDC3PO(10000, 19999)); robotStock.put(robot.getId(), robot); 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)) { - 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; }