RobotFactory Klasse erstellt und die Methode addRoboter implementiert

master
Milan Lukic 2023-01-04 12:46:13 +01:00
parent fbeda26182
commit 3bcff6941c
1 changed files with 30 additions and 0 deletions

View File

@ -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;
}
}