comments + added MagicValueException in C3PO
parent
58cac3d48a
commit
f8ce7fa3e8
|
@ -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;
|
||||
|
||||
/**
|
||||
* <h1>C3P0</h1>
|
||||
|
@ -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]) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue