Pr_robot_factory/domain/RobotBasics.java

93 lines
1.8 KiB
Java
Raw Normal View History

2022-12-09 00:29:00 +01:00
package domain;
import robot.exceptions.RobotException;
import robot.exceptions.RobotIllegalStateException;
import robot.interfaces.Robot;
2022-12-14 09:54:18 +01:00
import java.util.Arrays;
public class RobotBasics implements Robot {
2022-12-09 00:29:00 +01:00
private int id;
private String name;
private boolean power;
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() {
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
*/
@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-14 09:54:18 +01:00
* @see robot.interfaces.RobotInstructions
* Maybe method is depractable
*/
@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-14 09:54:18 +01:00
}
2022-12-09 00:29:00 +01:00
}