diff --git a/src/Main.java b/src/Main.java index 3430513..36fb4d0 100644 --- a/src/Main.java +++ b/src/Main.java @@ -10,12 +10,13 @@ public class Main { RobotType R2D2 = RobotType.R2D2; RobotType C3P0 = RobotType.C3P0; for (int i = 0; i < 10000; i++) { - rf.getRobot(R2D2, 0); + rf.getRobot(R2D2, "TestR2D2"); } System.out.println("finished R2D2"); for (int i = 0; i < 10000; i++) { - rf.getRobot(C3P0, 0); + rf.getRobot(C3P0, "TestC3P0"); } System.out.println("finished C3P0"); + System.out.println("finished"); } } \ No newline at end of file diff --git a/src/de/hsmannheim/informatik/name/domain/RobotFactory.java b/src/de/hsmannheim/informatik/name/domain/RobotFactory.java index 120c4df..286e12d 100644 --- a/src/de/hsmannheim/informatik/name/domain/RobotFactory.java +++ b/src/de/hsmannheim/informatik/name/domain/RobotFactory.java @@ -17,8 +17,8 @@ import java.util.Set; * @see RobotType */ public class RobotFactory { - private Set serialNumbersR2D2 = new HashSet<>(); - private Set serialNumbersC3P0 = new HashSet<>(); + private static Set serialNumbersR2D2 = new HashSet<>(); + private static Set serialNumbersC3P0 = new HashSet<>(); /** * Factory Method to get a {@link Robot} @@ -28,7 +28,7 @@ public class RobotFactory { * @return a {@link Robot robot instance} of specified type, if no type matches {@code null} * @throws RobotIllegalStateException the robot initializes in an illegal state */ - public Robot getRobot(RobotType type, int serialNumber) throws RobotIllegalStateException { + public Robot getRobot(RobotType type, String name) throws RobotIllegalStateException { Random r = new Random(); boolean usedSerialNumber = true; switch (type) { @@ -53,7 +53,7 @@ public class RobotFactory { usedSerialNumber = false; } }while(usedSerialNumber); - return new R2D2(serialNumberR2D2); + return new R2D2(serialNumberR2D2, name); } default -> { return null; diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java b/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java index 855bbd8..ab1589d 100644 --- a/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java +++ b/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java @@ -13,8 +13,8 @@ import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException; * @see StarWarsRobot */ public class R2D2 extends StarWarsRobot { - public R2D2(int id) throws RobotIllegalStateException { - super(',', id, "R2D2"); + public R2D2(int id, String name) throws RobotIllegalStateException { + super(',', id, name); } @Override