generated from hummel/Bank-System
JavaDoc+Anpassungen
parent
a243734c9b
commit
4c687759fd
|
@ -21,26 +21,20 @@ public class Nexus6 extends Robots {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String speak(int[] zahlen) throws RobotException {
|
public String speak(int[] zahlen) throws RobotException {
|
||||||
throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName());
|
throw new RobotIllegalStateException("Der Nexus6-Roboter: Pris ist ausgeschaltet!", this.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] think(int[] zahlen) throws RobotException {
|
public int[] think(int[] zahlen) throws RobotException {
|
||||||
throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName());
|
throw new RobotIllegalStateException("Der Nexus6-Roboter: Pris ist ausgeschaltet!", this.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public RobotException getLastException() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public RobotType getRobotType () {
|
public RobotType getRobotType () {
|
||||||
return this.robotType;
|
return this.robotType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,37 +8,28 @@ import tpe.exceptions.RobotMagicValueException;
|
||||||
|
|
||||||
public class R2D2 extends Robots {
|
public class R2D2 extends Robots {
|
||||||
RobotType robotType;
|
RobotType robotType;
|
||||||
private RobotException lastException;
|
|
||||||
private String name;
|
|
||||||
private boolean powerSwitch;
|
|
||||||
private int id;
|
private int id;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
/**
|
||||||
|
* Inititalisert R2D2 und weist {@link RobotType} zu
|
||||||
|
* @param name
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
public R2D2(String name,int id) {
|
public R2D2(String name,int id) {
|
||||||
super(name);
|
super(name);
|
||||||
this.id=id;
|
this.id=id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
robotType= RobotType.R2D2;
|
robotType= RobotType.R2D2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] think(int[] zahlen) throws RobotException {
|
public int[] think(int[] zahlen) throws RobotException {
|
||||||
if(!isPowerOn())
|
|
||||||
{
|
|
||||||
throw new RobotIllegalStateException("Der Roboter ist ausgeschaltet!", this.getName());
|
|
||||||
}
|
|
||||||
else if(checkRobotMagicValueException(zahlen)==true)
|
|
||||||
{
|
|
||||||
throw new RobotMagicValueException("Zahl 42 kann nicht verarbeitet werden!",this.getName());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Iterate through zahlen from left to right
|
// Iterate through zahlen from left to right
|
||||||
for (int i = 0; i < zahlen.length - 1; i++) {
|
for (int i = 0; i < zahlen.length - 1; i++) {
|
||||||
// Set the index of the current smallest element to i
|
// Set the index of the current smallest element to i
|
||||||
|
@ -55,9 +46,13 @@ public class R2D2 extends Robots {
|
||||||
zahlen[minIndex] = temp;
|
zahlen[minIndex] = temp;
|
||||||
}
|
}
|
||||||
return zahlen;
|
return zahlen;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Gibt {@link RobotType} zurück
|
||||||
|
*/
|
||||||
public RobotType getRobotType () {
|
public RobotType getRobotType () {
|
||||||
return this.robotType;
|
return this.robotType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,19 @@ public class RobotFactory {
|
||||||
private Robots nexus6=Nexus6.getInstance();
|
private Robots nexus6=Nexus6.getInstance();
|
||||||
private String factoryName;
|
private String factoryName;
|
||||||
private HashMap<Integer,Robots> robotStock=new HashMap<>();
|
private HashMap<Integer,Robots> robotStock=new HashMap<>();
|
||||||
|
/**
|
||||||
|
* <code>RobotFactory()</code> mit Namen <br />
|
||||||
|
* {@link Nexus6} in robotStock-HashMap als Standardmäßiger Roboter eingefügt
|
||||||
|
*/
|
||||||
public RobotFactory(String factoryName) {
|
public RobotFactory(String factoryName) {
|
||||||
this.factoryName=factoryName;
|
this.factoryName=factoryName;
|
||||||
robotStock.put(nexus6.getId(), nexus6);
|
robotStock.put(nexus6.getId(), nexus6);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* <code>constructRobot()</code> konstruiert Roboter mit durch Kunden gewählten Namen und fügt diese in die HashMap ein <br>
|
||||||
|
* Unterscheidung durch {@link RobotType}
|
||||||
|
* @return Id des erstellten Roboters
|
||||||
|
*/
|
||||||
public int constructRobot(RobotType robotType, String name) {
|
public int constructRobot(RobotType robotType, String name) {
|
||||||
Robots robot;
|
Robots robot;
|
||||||
|
|
||||||
|
@ -29,7 +36,11 @@ public class RobotFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* RoboterID wird über Math.random() erstellt entsprechend der Anforderung variiert der Zahlenbereich
|
||||||
|
* @param value
|
||||||
|
* @return ID für die in <code>constructRobot()</code> erstellten Roboter
|
||||||
|
*/
|
||||||
private int createIDR2D2(int value) {
|
private int createIDR2D2(int value) {
|
||||||
|
|
||||||
int randomID = (int) (Math.random()*(value)) ;
|
int randomID = (int) (Math.random()*(value)) ;
|
||||||
|
@ -48,49 +59,89 @@ public class RobotFactory {
|
||||||
}
|
}
|
||||||
return randomID;
|
return randomID;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Gibt den Namen der Fabrik zurück
|
||||||
|
*/
|
||||||
public String getFactoryName() {
|
public String getFactoryName() {
|
||||||
return factoryName;
|
return factoryName;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Durchsucht die HashMap über Object Key in diesem Fall die Roboter ID
|
||||||
|
* @param id
|
||||||
|
* @return Gibt den zur entsprechenden ID gefunden Roboter zurück
|
||||||
|
*/
|
||||||
public Robots getRobot(int id) {
|
public Robots getRobot(int id) {
|
||||||
return robotStock.get(id);
|
return robotStock.get(id);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Schaltet den Roboter an bzw. aus und ruft Methode aus {@link Robots} auf
|
||||||
|
* @param id
|
||||||
|
* @return Rückgabe ob Roboter an ist true=an false=aus
|
||||||
|
*/
|
||||||
public boolean triggerPower(int id) {
|
public boolean triggerPower(int id) {
|
||||||
Robots robot=getRobot(id);
|
Robots robot=getRobot(id);
|
||||||
robot.triggerPowerSwitch();
|
robot.triggerPowerSwitch();
|
||||||
return robot.powerStatus;
|
return robot.powerStatus;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return Rückgabe ob Roboter an ist true=an false=aus
|
||||||
|
*/
|
||||||
public boolean powerStatus(int id) {
|
public boolean powerStatus(int id) {
|
||||||
Robots robot=getRobot(id);
|
Robots robot=getRobot(id);
|
||||||
return robot.powerStatus;
|
return robot.powerStatus;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Sucht die Informationen zum über die ID gesuchten Roboter aus der HashMap
|
||||||
|
* @param id
|
||||||
|
* @return Gibt die Informationen zum über die ID gesuchten Roboter aus
|
||||||
|
*/
|
||||||
public String robotInfo(int id) {
|
public String robotInfo(int id) {
|
||||||
Robots robot=getRobot(id);
|
Robots robot=getRobot(id);
|
||||||
return robot.toString();
|
return robot.toString();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Ermöglicht Roboter zur jeweiligen ID aus der HashMap zu löschen => Roboter Instanz löschen
|
||||||
|
* @param id
|
||||||
|
* @return Bei null wurde kein Roboter zur ID gefunden falls Roboter zurückgegeben wird ist dieser gelöscht
|
||||||
|
*/
|
||||||
public Robots dismantleRobot(int id) {
|
public Robots dismantleRobot(int id) {
|
||||||
return robotStock.remove(id);
|
return robotStock.remove(id);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Sucht den Roboter zur ID aus der HashMap und ermittelt über {@link Robots} Funktion die {@link RobotException}
|
||||||
|
* @param id
|
||||||
|
* @return Gibt {@link RobotException} zurück
|
||||||
|
*/
|
||||||
public RobotException robotBlackbox(int id) {
|
public RobotException robotBlackbox(int id) {
|
||||||
Robots robot=getRobot(id);
|
Robots robot=getRobot(id);
|
||||||
return robot.getLastException();
|
return robot.getLastException();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Ruft die definierten Funktionalitäten aus {@link RobotInstructions} auf
|
||||||
|
* @param id
|
||||||
|
* @param zahlen
|
||||||
|
* @return Ergebnis der Instructions bei Fehler einer {@link RobotException}
|
||||||
|
* @throws RobotException
|
||||||
|
*/
|
||||||
public String robotInstructions(int id, int[]zahlen) throws RobotException {
|
public String robotInstructions(int id, int[]zahlen) throws RobotException {
|
||||||
Robots robot=getRobot(id);
|
Robots robot=getRobot(id);
|
||||||
return robot.speak(robot.think(zahlen));
|
return robot.speak(robot.think(zahlen));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Gibt die Größe der HashMap zurück
|
||||||
|
*/
|
||||||
public int robotStockSize() {
|
public int robotStockSize() {
|
||||||
return robotStock.size();
|
return robotStock.size();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Prüft ob Roboter mit übergebener ID existiert
|
||||||
|
* @param id
|
||||||
|
* @return True=Roboter existier; False=Roboter existiert nicht
|
||||||
|
*/
|
||||||
public boolean containsRobot(int id) {
|
public boolean containsRobot(int id) {
|
||||||
return robotStock.containsKey(id);
|
return robotStock.containsKey(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,10 @@ public abstract class Robots implements Robot{
|
||||||
protected String name;
|
protected String name;
|
||||||
protected RobotException error;
|
protected RobotException error;
|
||||||
protected boolean powerStatus;
|
protected boolean powerStatus;
|
||||||
|
/**
|
||||||
|
* Legt fest das ein Roboter standardmäßig einen Namen hat und setzt den Power Knopf bei Erstellung auf aus
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
public Robots(String name) {
|
public Robots(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.powerStatus = false;
|
this.powerStatus = false;
|
||||||
|
@ -49,7 +52,6 @@ public abstract class Robots implements Robot{
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String speak(int[] zahlen) throws RobotException {
|
public String speak(int[] zahlen) throws RobotException {
|
||||||
|
|
||||||
if(powerStatus==false)
|
if(powerStatus==false)
|
||||||
|
|
Loading…
Reference in New Issue