Pr_robot_factory/domain/C3PO.java

46 lines
1.1 KiB
Java
Raw Normal View History

2022-12-08 14:58:44 +01:00
package domain;
2022-12-14 09:54:18 +01:00
import robot.exceptions.RobotException;
import robot.exceptions.RobotIllegalStateException;
import robot.exceptions.RobotMagicValueException;
import java.util.Arrays;
import java.util.stream.Collectors;
2022-12-09 00:30:35 +01:00
public class C3PO extends RobotBasics {
public C3PO(int id, String name){
super(id, name);
}
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 RobotMagicValueException(getName() + " has an unknown Error. Code 42.");
}
}
@Override
public String speak(int[] zahlen) throws RobotException {
//Insertionsort
if(isPowerOn()){
try{
return ausgabe(zahlen);
}catch(RobotException re){
return re.toString();
}
}else{
throw new RobotIllegalStateException(getName() + " is turned off.");
}
}
2022-12-14 09:54:18 +01:00
@Override
public int[] think(int[] zahlen) throws RobotException {
return new int[0];
2022-12-14 09:54:18 +01:00
}
}