diff --git a/Roboter/tpe/exceptions/roboter/C3PO.java b/Roboter/tpe/exceptions/roboter/C3PO.java index f1e9788..f031afc 100644 --- a/Roboter/tpe/exceptions/roboter/C3PO.java +++ b/Roboter/tpe/exceptions/roboter/C3PO.java @@ -2,7 +2,7 @@ package tpe.exceptions.roboter; import tpe.exceptions.roboter.exceptions.RobotException; -public class C3PO implements RobotControl, RobotInstructions{ +public class C3PO implements Robot{ @Override public String speak(int[] zahlen) { diff --git a/Roboter/tpe/exceptions/roboter/R2D2.java b/Roboter/tpe/exceptions/roboter/R2D2.java index ed51fe1..392a7a2 100644 --- a/Roboter/tpe/exceptions/roboter/R2D2.java +++ b/Roboter/tpe/exceptions/roboter/R2D2.java @@ -2,13 +2,12 @@ package tpe.exceptions.roboter; import java.util.*; import tpe.exceptions.roboter.exceptions.RobotException; -import tpe.exceptions.roboter.exceptions.RobotMagicValueException; -public class R2D2 implements RobotControl, RobotInstructions { +public class R2D2 implements Robot { + RobotException robotexception; private String name; private boolean powerSwitch; private int id; - private RobotMagicValueException robotMagicValueException; StringBuilder sb = new StringBuilder(); public R2D2(String name, boolean powerSwitch) { @@ -52,10 +51,8 @@ public class R2D2 implements RobotControl, RobotInstructions { } @Override - public String speak(int[] zahlen) { - if(robotMagicValueException.invalidNumber(zahlen)==true) - return "42 ist keine gültige Eingabe"; - else { + public String speak(int[] zahlen) throws RobotException { + for (int i = 0; i < zahlen.length; i++) { sb.append(zahlen[i]); if (i < zahlen.length - 1) { @@ -65,11 +62,14 @@ public class R2D2 implements RobotControl, RobotInstructions { String output = sb.toString(); return output; - } + } - @Override - public int[] think(int[] zahlen) { + public int[] think(int[] zahlen) throws RobotException { + for(int i = 0; i < zahlen.length; i++) { + if(zahlen[i]==42) + throw new RobotException.MagicValueException(); + } // Iterate through zahlen from left to right for (int i = 0; i < zahlen.length - 1; i++) { // Set the index of the current smallest element to i @@ -86,6 +86,7 @@ public class R2D2 implements RobotControl, RobotInstructions { zahlen[minIndex] = temp; } return zahlen; + } }