Pr_robot_factory/domain/RobotBasics.java

84 lines
1.5 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;
import robot.interfaces.RobotControl;
import robot.interfaces.RobotInstructions;
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
/**
* @see RobotControl
2022-12-09 00:29:00 +01:00
*/
@Override
public int getId() {
return id;
}
/**
* @see RobotControl
2022-12-09 00:29:00 +01:00
*/
@Override
public String getName() {
return name;
}
/**
* @see 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
}
/**
* @see RobotControl
2022-12-09 00:29:00 +01:00
*/
@Override
public boolean isPowerOn() {
return power;
}
/**
* @see RobotInstructions
2022-12-09 00:29:00 +01:00
*/
@Override
public String speak(int[] zahlen) throws RobotException {
if(power == true){
String array = "";
for(int i = 0; i < zahlen.length; i++){
array += zahlen[i] + " ";
}
return array;
2022-12-09 00:29:00 +01:00
}else{
throw new RobotIllegalStateException("The Robot is turned off.");
2022-12-09 00:29:00 +01:00
}
}
/**
* @see RobotInstructions
*/
@Override
public int[] think(int[] zahlen) throws RobotException {
return new int[0];
2022-12-09 00:29:00 +01:00
}
2022-12-09 00:29:00 +01:00
}