61 lines
1.8 KiB
Java
61 lines
1.8 KiB
Java
package domain;
|
|
|
|
import safety.robot_exceptions.ExceptionStorage;
|
|
import safety.robot_exceptions.RobotException;
|
|
import safety.robot_exceptions.robotExceptions;
|
|
|
|
public class C3PO extends Robot {
|
|
public C3PO(int id, String name){
|
|
super(id, name, "C3PO");
|
|
|
|
}
|
|
|
|
/* public String ausgabe(int[] input) throws RobotException{
|
|
if(input.length != 0 && !checkArray(input)){
|
|
return Arrays.stream(input)
|
|
.mapToObj(Integer::toString)
|
|
.collect(Collectors.joining("; "));
|
|
}else{
|
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
|
// throw new RobotMagicValueException(getName() + " has an unknown Error. Code 42.");
|
|
}
|
|
}*/
|
|
@Override
|
|
public String speak(int[] input) throws RobotException {
|
|
if(isPowerOn()){
|
|
try{
|
|
return ausgabe(input, ";");
|
|
}catch(RobotException re){
|
|
return re.toString();
|
|
}
|
|
}else{
|
|
RobotException robotException = new RobotException(robotExceptions.ILLEGALSTATE, getName());
|
|
this.exceptions = new ExceptionStorage(robotException);
|
|
throw robotException;
|
|
}
|
|
|
|
}
|
|
|
|
public int[] sorting(int[] input) throws RobotException{
|
|
if(checkArray(input)){
|
|
return insertionSort(input);
|
|
}else{
|
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
|
//throw new RobotMagicValueException(getName() + " has an unknown error. Code 42");
|
|
}
|
|
}
|
|
@Override
|
|
public int[] think(int[] input) throws RobotException {
|
|
//Insertionsort
|
|
if(isPowerOn()){
|
|
return sorting(input);
|
|
}else{
|
|
throw new RobotException(robotExceptions.ILLEGALSTATE, getName());
|
|
// throw new RobotIllegalStateException(getName() + " is turned off.");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|