From dbb7419f1ea937fe449d2883aaee1c512b9eea66 Mon Sep 17 00:00:00 2001 From: 2120940 <2120940@stud.hs-mannheim.de> Date: Sat, 7 Jan 2023 14:10:45 +0100 Subject: [PATCH] =?UTF-8?q?implements=20zu=20Robot=20ge=C3=A4ndert=20nach?= =?UTF-8?q?=20Anforderungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Roboter/tpe/exceptions/roboter/C3PO.java | 2 +- Roboter/tpe/exceptions/roboter/R2D2.java | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) 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; + } }