package tpe.exceptions.roboter; import java.util.HashMap; public class RobotFactory { private Nexus6 nexus6=Nexus6.getInstance(); private HashMap robotStock=new HashMap<>(); public int constructRobot(RobotType robotType, String name) { Robots robot; if(RobotType.R2D2==robotType) { robot=new R2D2(name, checkID(0,9999)); robotStock.put(robot.getId(), robot); return robot.getId(); }else if(RobotType.C3PO==robotType) { robot=new C3PO(name, checkID()); robotStock.put(robot.getId(), robot); return robot.getId(); } } private int checkID(int minValue, int maxValue) { int randomID = (int) (Math.random()*(maxValue - minValue)) + minValue; if(robotStock.containsKey(randomID)) { checkID(minValue,maxValue); } return randomID; } }