package facade; import java.util.HashMap; import Domäne.C3PO; import Domäne.R2D2; import Domäne.RobotFactory; import Domäne.RobotType; import Domäne.Roboter; public class Factorysystem { private RobotFactory robotFactory; public HashMap roboterLager = new HashMap<>(); public Factorysystem (String name) { this.robotFactory = new RobotFactory (name); } public int roboterAnlegen (String name, int auswahl) { RobotType robottype; if(auswahl == 1) { robottype = RobotType.R2D2; int id = idVergeben(0, 9999); robotFactory.addRobot(robottype, name, id); return id; } else if(auswahl == 2) { robottype = RobotType.C3PO; int id = idVergeben(10000, 19999); robotFactory.addRobot(robottype, name, id); return id; } roboterLager.put(id, r); } private int idVergeben(int min, int max) { int randomValue = (int) (Math.random()*(max - min)) + min; if (roboterLager.containsKey(randomValue)) { idVergeben(min, max); } return randomValue; } }