package domain; import robot.exceptions.RobotException; import robot.exceptions.RobotIllegalStateException; import robot.interfaces.Robot; import java.util.Arrays; public class RobotBasics implements Robot { private int id; private String name; private boolean power; public RobotBasics(int id, String name){ this.id = id; this.name = name; this.power = false; } /** * @see robot.interfaces.RobotControl; */ @Override public int getId() { return id; } /** * @see robot.interfaces.RobotControl; */ @Override public String getName() { return name; } /** * @see robot.interfaces.RobotControl; */ @Override public void triggerPowerSwitch() { if(power == false){ power = true; }else{ power = false; } } /** * @see robot.interfaces.RobotControl; */ @Override public boolean isPowerOn() { return power; } /** * @see robot.interfaces.RobotControl; */ @Override public RobotException getLastException() { return null; } /** * @see robot.interfaces.RobotInstructions; * Maybe method is depractable */ @Override public String speak(int[] zahlen) throws RobotException { if(isPowerOn() == true){ final String[] array = {""}; Arrays.stream(zahlen).forEach(i -> array[0] += i + ", "); return array[0]; }else{ throw new RobotIllegalStateException( name + " is turned off."); } } /** * @see robot.interfaces.RobotInstructions * Maybe method is depractable */ @Override public int[] think(int[] zahlen) throws RobotException { if(isPowerOn() == true){ return zahlen; }else{ throw new RobotIllegalStateException(name + " is turned off"); } } }