Pr_robot_factory/domain/RobotBasics.java

76 lines
1.4 KiB
Java
Raw Normal View History

2022-12-09 00:29:00 +01:00
package domain;
import roboter.exceptions.RobotException;
import roboter.exceptions.RobotIllegalStateException;
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 domain.RobotControl
*/
@Override
public int getId() {
return id;
}
/**
* @see domain.RobotControl
*/
@Override
public String getName() {
return name;
}
/**
* @see domain.RobotControl
*/
@Override
public void triggerPowerSwitch() {
if(power == false){
power = true;
}else{
power = false;
}
2022-12-09 00:29:00 +01:00
}
/**
* @see domain.RobotControl
*/
@Override
public boolean isPowerOn() {
return power;
}
/**
* @see roboter.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 roboter.RobotInstructions
*/
@Override
public int[] think(int[] zahlen) throws RobotException {
return new int[0];
2022-12-09 00:29:00 +01:00
}
}