diff --git a/Roboterfabrik/src/Domäne/C3PO.java b/Roboterfabrik/src/Domäne/C3PO.java index 958df77..13318f3 100644 --- a/Roboterfabrik/src/Domäne/C3PO.java +++ b/Roboterfabrik/src/Domäne/C3PO.java @@ -11,7 +11,7 @@ public class C3PO extends Roboter { RobotType robotType; RobotException fehler; - C3PO(String name, int id) { + public C3PO(String name, int id) { super(name); this.robotType = robotType.C3PO; this.id = id; diff --git a/Roboterfabrik/src/Domäne/R2D2.java b/Roboterfabrik/src/Domäne/R2D2.java index 4566db0..c336977 100644 --- a/Roboterfabrik/src/Domäne/R2D2.java +++ b/Roboterfabrik/src/Domäne/R2D2.java @@ -13,7 +13,7 @@ public class R2D2 extends Roboter { private RobotType robotType; RobotException fehler; - R2D2(String name, int id) { + public R2D2(String name, int id) { super(name); this.robotType = RobotType.R2D2; this.id = id; diff --git a/Roboterfabrik/src/ui/Factory.java b/Roboterfabrik/src/ui/Factory.java index fd8e8af..98c8950 100644 --- a/Roboterfabrik/src/ui/Factory.java +++ b/Roboterfabrik/src/ui/Factory.java @@ -2,11 +2,11 @@ package ui; import java.util.Scanner; +import Domäne.C3PO; +import Domäne.R2D2; import Domäne.Roboter; -import java.util.Collection; import java.util.HashMap; -import java.util.Random; public class Factory { Scanner sc = new Scanner(System.in); @@ -55,6 +55,8 @@ public class Factory { } private void roboterBauen() { + Roboter r = null; + int id = 0; System.out.println("Welchen Robotertyp möchten Sie haben?(R2D2(1) oder C3PO (2)"); int auswahl = Integer.parseInt(sc.nextLine()); @@ -62,15 +64,24 @@ public class Factory { String name = sc.nextLine(); if(auswahl == 1) { - roboterLager.put(idVergeben(0, 9999), R2D2 roboter = new R2D2(name); + id = idVergeben(0, 9999); + r = new R2D2(name, id); } else if(auswahl == 2) { - + id = idVergeben(10000, 19999); + r = new C3PO(name, id); } + roboterLager.put(id, r); } private int idVergeben(int min, int max) { - return 0; + + int randomValue = (int) (Math.random()*(max - min)) + min; + if (roboterLager.containsKey(randomValue)) { + idVergeben(min, max); + } + + return randomValue; }