2022-12-08 14:58:44 +01:00
|
|
|
package domain;
|
|
|
|
|
2023-01-02 19:51:04 +01:00
|
|
|
import safety.robot_exceptions.ExceptionStorage;
|
|
|
|
import safety.robot_exceptions.RobotException;
|
|
|
|
import safety.robot_exceptions.robotExceptions;
|
2022-12-20 12:03:41 +01:00
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
public class C3PO extends Robot {
|
2022-12-08 23:13:22 +01:00
|
|
|
public C3PO(int id, String name){
|
2023-01-03 01:18:57 +01:00
|
|
|
super(id, name, "C3PO");
|
|
|
|
|
2022-12-08 23:13:22 +01:00
|
|
|
}
|
|
|
|
|
2022-12-25 19:57:20 +01:00
|
|
|
/* 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.");
|
|
|
|
}
|
|
|
|
}*/
|
2022-12-20 12:03:41 +01:00
|
|
|
@Override
|
2022-12-21 16:44:49 +01:00
|
|
|
public String speak(int[] input) throws RobotException {
|
2022-12-20 12:03:41 +01:00
|
|
|
if(isPowerOn()){
|
|
|
|
try{
|
2022-12-22 12:29:04 +01:00
|
|
|
return ausgabe(input, ";");
|
2022-12-20 12:03:41 +01:00
|
|
|
}catch(RobotException re){
|
|
|
|
return re.toString();
|
|
|
|
}
|
|
|
|
}else{
|
2022-12-25 19:57:20 +01:00
|
|
|
RobotException robotException = new RobotException(robotExceptions.ILLEGALSTATE, getName());
|
|
|
|
this.exceptions = new ExceptionStorage(robotException);
|
|
|
|
throw robotException;
|
2022-12-20 12:03:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-12-21 16:44:49 +01:00
|
|
|
|
|
|
|
public int[] sorting(int[] input) throws RobotException{
|
|
|
|
if(checkArray(input)){
|
2022-12-22 12:29:04 +01:00
|
|
|
return insertionSort(input);
|
2022-12-21 16:44:49 +01:00
|
|
|
}else{
|
|
|
|
throw new RobotException(robotExceptions.MAGICVALUE, getName());
|
|
|
|
//throw new RobotMagicValueException(getName() + " has an unknown error. Code 42");
|
|
|
|
}
|
|
|
|
}
|
2022-12-14 09:54:18 +01:00
|
|
|
@Override
|
2022-12-21 16:44:49 +01:00
|
|
|
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.");
|
|
|
|
}
|
2022-12-14 09:54:18 +01:00
|
|
|
}
|
2022-12-20 12:03:41 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 10:45:51 +01:00
|
|
|
|
|
|
|
|