RobotFactory/src/de/hsmannheim/informatik/name/domain/RobotBluePrint.java

66 lines
1.7 KiB
Java

package de.hsmannheim.informatik.name.domain;
import de.hsmannheim.informatik.name.domain.exceptions.RobotException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException;
import de.hsmannheim.informatik.name.domain.requirements.Robot;
public abstract class RobotBluePrint implements Robot {
protected final int ID;
protected final int MAGIC_NUMBER = 42;
private final String name;
private boolean isPowered;
public RobotBluePrint(int id, String name) throws RobotIllegalStateException {
if (!this.isValidID(id)) {
//TODO write own Exception
throw new RobotIllegalStateException();
}
this.ID = id;
this.name = name;
this.isPowered = false;
}
/**
* Checks if an {@code int} represents a valid {@code ID},
* concerning a specific model within its own criteria
*
* @param id {@code ID} to check
* @return {@code true} if the ID is valid, else {@code false}
*/
protected abstract boolean isValidID(int id);
@Override
public int getId() {
return this.ID;
}
@Override
public String getName() {
return this.name;
}
@Override
public void triggerPowerSwitch() {
this.isPowered = !this.isPowered;
}
@Override
public boolean isPowerOn() {
return this.isPowered;
}
@Override
public RobotException getLastException() {
return null;
}
@Override
public abstract String speak(int[] zahlen) throws RobotException, RobotMagicValueException;
@Override
public abstract int[] think(int[] zahlen) throws RobotException, RobotMagicValueException;
}