Pr_robot_factory/domain/R2D2.java

73 lines
2.0 KiB
Java

package domain;
import robot.exceptions.ExceptionStorage;
import robot.exceptions.RobotException;
import robot.exceptions.robotExceptions;
public class R2D2 extends RobotBasics {
/**
*
* @param id> int
* @param name> String
*/
public R2D2(int id, String name){
super(id, name);
}
public int[] think(int[] input) throws RobotException {
if(isPowerOn()){
return selectionSort(input);
}else{
this.exceptions = new ExceptionStorage( new RobotException(robotExceptions.ILLEGALSTATE, getName()));
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
}
}
/*
* this method sorts
* @param input
* @return integer array
* @throws RobotException
public int[] sorting(int[] input) throws RobotException {
if(checkArray(input)){
//Selectionsort
int small;
for (int i = 0; i <input.length - 1; i++) {
small = i;
for (int j = i + 1; j < input.length; j++) {
//if there is a smaller number on this position
if (input[j] < input[small]) {
small = j;
//swap values
int temp = input[i];
input[i] = input[small];
input[small] = temp;
}
}
}
return input;
}else{
throw new RobotException(robotExceptions.MAGICVALUE, getName());
}
}*/
/**
* Die Methode nimmt ein Array aus int entgegen und wandelt diese in einen String um.
* @param input Zahlen, die ausgegeben werden sollen.
* @return String oder null
* @throws RobotException
*/
@Override
public String speak(int[] input) throws RobotException {
if (isPowerOn()) {
return ausgabe(input, ";");
} else {
this.exceptions = new ExceptionStorage( new RobotException(robotExceptions.ILLEGALSTATE, getName()));
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
}
}
}