diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java b/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java index 9c429b5..3843f6b 100644 --- a/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java +++ b/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java @@ -2,6 +2,7 @@ package de.hsmannheim.informatik.name.domain.starwars; import de.hsmannheim.informatik.name.domain.exceptions.RobotException; import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException; +import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException; /** *

C3P0

@@ -21,9 +22,21 @@ public class C3PO extends StarWarsRobot { return 10000 <= id && id <= 19999; } + /** + * C3PO think method sorts numbers with insertion sort in descending order + * @param numbers integer numbers for sorting + * @return arrToSort integer array with numbers sorted in descending order + * @throws RobotException + */ @Override - public int[] think(int[] zahlen) throws RobotException { - int[] arrToSort = zahlen.clone(); + //TODO why is RobotMagicValueException grayed out? + public int[] think(int[] numbers) throws RobotException, RobotMagicValueException { + int[] arrToSort = numbers.clone(); + for (int i = 0; i < arrToSort.length; i++) { + if (arrToSort[i] == MAGIC_NUMBER) { + throw new RobotMagicValueException(String.format("Appearance of Magic Number: %d", MAGIC_NUMBER), this); + } + } for (int i = 1; i < arrToSort.length; i++) { for (int j = i; j > 0; j--) { if (arrToSort[j - 1] > arrToSort[j]) { diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java b/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java index 998d0b9..7650119 100644 --- a/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java +++ b/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java @@ -23,7 +23,7 @@ public class R2D2 extends StarWarsRobot { } /** - * R2D2 think method sorts numbers with selection sort + * R2D2 think method sorts numbers with selection sort in ascending order * @param numbers integer numbers for sorting * @return arrayToSort integer array with numbers sorted in ascending order * @throws RobotException diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java b/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java index 497181a..7b43d1b 100644 --- a/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java +++ b/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java @@ -24,12 +24,19 @@ public abstract class StarWarsRobot extends RobotBluePrint { SEPARATOR = separator; } + /** + * Speak method checks for occurrence of Magic Number, if the number is not in the input array, + * the input gets returned after applying the method buildString + * @param numbers integer numbers for output + * @return String with for robot type matching seperator + * @throws RobotException + */ @Override - public String speak(int[] zahlen) throws RobotException { - if (Arrays.stream(zahlen).anyMatch(i -> i == MAGIC_NUMBER)) { + public String speak(int[] numbers) throws RobotException { + if (Arrays.stream(numbers).anyMatch(i -> i == MAGIC_NUMBER)) { throw new RobotMagicValueException(String.format("Appearance of Magic Number: %d", MAGIC_NUMBER), this); } - return this.buildString(zahlen); + return this.buildString(numbers); } /**