diff --git a/Roboter/tpe/exceptions/roboter/R2D2.java b/Roboter/tpe/exceptions/roboter/R2D2.java index cb57b29..b35e9c4 100644 --- a/Roboter/tpe/exceptions/roboter/R2D2.java +++ b/Roboter/tpe/exceptions/roboter/R2D2.java @@ -1,12 +1,15 @@ package tpe.exceptions.roboter; import tpe.exceptions.roboter.exceptions.RobotException; +import tpe.exceptions.roboter.exceptions.RobotMagicValueException; public class R2D2 implements RobotControl, RobotInstructions { private static int counter = 0; private String name; private boolean powerSwitch; private int id; + private RobotMagicValueException robotMagicValueException; + StringBuilder sb = new StringBuilder(); public R2D2(String name, boolean powerSwitch) { super(); @@ -17,6 +20,7 @@ public class R2D2 implements RobotControl, RobotInstructions { @Override public int getId() { + return id; } @@ -46,8 +50,19 @@ public class R2D2 implements RobotControl, RobotInstructions { @Override public String speak(int[] zahlen) { - // TODO Auto-generated method stub - return null; + if(robotMagicValueException.invalidNumber(zahlen)==true) + return "42 ist keine gültige Eingabe"; + else { + for (int i = 0; i < zahlen.length; i++) { + sb.append(zahlen[i]); + if (i < zahlen.length - 1) { + sb.append(", "); + } + } + + String output = sb.toString(); + return output; + } } @Override @@ -69,5 +84,5 @@ public class R2D2 implements RobotControl, RobotInstructions { } return zahlen; } - + } diff --git a/Roboter/tpe/exceptions/roboter/exceptions/RobotException.java b/Roboter/tpe/exceptions/roboter/exceptions/RobotException.java index a7c8afa..6b7ae91 100644 --- a/Roboter/tpe/exceptions/roboter/exceptions/RobotException.java +++ b/Roboter/tpe/exceptions/roboter/exceptions/RobotException.java @@ -1,5 +1,6 @@ package tpe.exceptions.roboter.exceptions; public class RobotException { + } diff --git a/Roboter/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java b/Roboter/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java index 853d4fa..84dae3d 100644 --- a/Roboter/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java +++ b/Roboter/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java @@ -1,5 +1,16 @@ package tpe.exceptions.roboter.exceptions; -public class RobotMagicValueException { +public class RobotMagicValueException { + + public boolean invalidNumber(int[] zahlen) { + + boolean error=false; + for(int i =0; i