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