From 6415b936c71637bb5b2eb93acd0fe0839e8bfc1e Mon Sep 17 00:00:00 2001 From: azadehobenland Date: Thu, 5 Jan 2023 18:48:22 +0100 Subject: [PATCH] R2D2 Sortieralgorithmus angepasst --- src/Nexus6.java | 43 +++++-------------- .../roboter/exceptions/RobotException.java | 3 ++ .../RobotIllegalStateException.java | 9 +++- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/Nexus6.java b/src/Nexus6.java index 1338ab1..66db374 100644 --- a/src/Nexus6.java +++ b/src/Nexus6.java @@ -19,10 +19,11 @@ public class Nexus6 implements Robot { public static Nexus6 getInstance() { - if (instance == null) - instance = new Nexus6(); - return instance; - } + if (instance == null) { + instance = new Nexus6(); + } + return instance; + } @Override @@ -37,11 +38,7 @@ public class Nexus6 implements Robot { @Override public void triggerPowerSwitch() { - if(isPowerOn==false){ - isPowerOn=true; - }else{ - isPowerOn=false; - } + } @@ -56,33 +53,15 @@ public class Nexus6 implements Robot { } @Override - public String speak(int[] zahlen) /*throws RobotIllegalStateException */{ + public String speak(int[] zahlen) throws RobotIllegalStateException { + throw new RobotIllegalStateException(this); - var sortiert = think(zahlen); - - return arrayFormatieren(sortiert); } - private String arrayFormatieren(int[] zahlen){ - var ergebnis = Arrays.stream(zahlen) - .boxed() - .map(String::valueOf) - .collect(Collectors.joining(",")); - return ergebnis; - } + @Override - public int[] think(int[] zahlen) /*throws RobotIllegalStateException*/ { - int n = zahlen.length; - for (int i = 1; i < n; ++i) { - int key = zahlen[i]; - int j = i - 1; - while (j >= 0 && zahlen[j] < key) { - zahlen[j + 1] = zahlen[j]; - j = j - 1; - } - zahlen[j + 1] = key; - } - return zahlen; + public int[] think(int[] zahlen) throws RobotIllegalStateException { + throw new RobotIllegalStateException(this); } diff --git a/src/tpe/exceptions/roboter/exceptions/RobotException.java b/src/tpe/exceptions/roboter/exceptions/RobotException.java index 435b2ed..df41be7 100644 --- a/src/tpe/exceptions/roboter/exceptions/RobotException.java +++ b/src/tpe/exceptions/roboter/exceptions/RobotException.java @@ -1,4 +1,7 @@ package tpe.exceptions.roboter.exceptions; public class RobotException extends Exception{ + public RobotException(String errormessage) { + super(errormessage); + } } diff --git a/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java b/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java index 788ecf5..f0e751c 100644 --- a/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java +++ b/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java @@ -1,4 +1,11 @@ package tpe.exceptions.roboter.exceptions; -public class RobotIllegalStateException { +import tpe.exceptions.roboter.Robot; + +public class RobotIllegalStateException extends RobotException { + + public RobotIllegalStateException(Robot roboter) { + + super("Fehler von : " + roboter.getName()); + } }