package domain; import utility.robot_exceptions.ExceptionStorage; import utility.robot_exceptions.RobotException; import utility.robot_exceptions.robotExceptions; public class R2D2 extends Robot { /** * * @param id> int * @param name> String */ public R2D2(int id, String name){ super(id, name, "R2D2"); } /** * @see utility.interfaces.RobotInstructions */ public int[] think(int[] input) throws RobotException { if(isPowerOn()){ return selectionSort(input); }else{ RobotException robotexception = new RobotException(robotExceptions.ILLEGALSTATE, getName()); this.exceptions = new ExceptionStorage(robotexception); throw robotexception; } } /** * Sorts any given array of integers with the selection Sort algorithm. * @param input * @return * @throws RobotException */ public int[] selectionSort(int[] input) throws RobotException{ if(checkArray(input)){ int small; for(int i = 0; i < input.length; i++){ small = i; for(int j = i + 1; j < input.length; j++){ if(input[j] < input[small]){ small = j; // System.out.println(small); } } int temp = input[i]; input[i] = input[small]; input[small] = temp; } return input; }else{ RobotException robotexception = new RobotException(robotExceptions.MAGICVALUE, getName()); this.exceptions = new ExceptionStorage(robotexception); throw robotexception; } } /** * @see utility.interfaces.RobotInstructions */ @Override public String speak(int[] input) throws RobotException { if (isPowerOn()) { return ausgabe(input, ";"); } else { RobotException robotexception = new RobotException(robotExceptions.ILLEGALSTATE, getName()); this.exceptions = new ExceptionStorage(robotexception); throw robotexception; } } }