RobotFactory Klasse erstellt und die Methode addRoboter implementiert
parent
fbeda26182
commit
3bcff6941c
|
@ -0,0 +1,30 @@
|
|||
package Domäne;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RobotFactory {
|
||||
private String name;
|
||||
private HashMap <Integer, Roboter> roboters = new HashMap<>();
|
||||
|
||||
public RobotFactory (String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int addRoboter (RobotType robotType) {
|
||||
Roboter roboter;
|
||||
|
||||
if (RobotType.R2D2 == robotType) {
|
||||
roboter = new R2D2 ("R2D2");
|
||||
roboters.put(roboter.getId(), roboter);
|
||||
return roboter.getId();
|
||||
}
|
||||
else if (RobotType.C3PO == robotType) {
|
||||
roboter = new C3PO ("C3PO");
|
||||
roboters.put(roboter.getId(), roboter);
|
||||
return roboter.getId();
|
||||
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue