Pr_robot_factory/domain/RobotBasics.java

84 lines
1.5 KiB
Java

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 {
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 RobotControl
*/
@Override
public int getId() {
return id;
}
/**
* @see RobotControl
*/
@Override
public String getName() {
return name;
}
/**
* @see RobotControl
*/
@Override
public void triggerPowerSwitch() {
if(power == false){
power = true;
}else{
power = false;
}
}
/**
* @see RobotControl
*/
@Override
public boolean isPowerOn() {
return power;
}
/**
* @see RobotInstructions
*/
@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;
}else{
throw new RobotIllegalStateException("The Robot is turned off.");
}
}
/**
* @see RobotInstructions
*/
@Override
public int[] think(int[] zahlen) throws RobotException {
return new int[0];
}
}