Ids werden jetzt zufällig vergeben und die Roboter werden in
roboterLager gespeichert.master
parent
4ec9407bfe
commit
28af833e03
|
@ -11,7 +11,7 @@ public class C3PO extends Roboter {
|
||||||
RobotType robotType;
|
RobotType robotType;
|
||||||
RobotException fehler;
|
RobotException fehler;
|
||||||
|
|
||||||
C3PO(String name, int id) {
|
public C3PO(String name, int id) {
|
||||||
super(name);
|
super(name);
|
||||||
this.robotType = robotType.C3PO;
|
this.robotType = robotType.C3PO;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class R2D2 extends Roboter {
|
||||||
private RobotType robotType;
|
private RobotType robotType;
|
||||||
RobotException fehler;
|
RobotException fehler;
|
||||||
|
|
||||||
R2D2(String name, int id) {
|
public R2D2(String name, int id) {
|
||||||
super(name);
|
super(name);
|
||||||
this.robotType = RobotType.R2D2;
|
this.robotType = RobotType.R2D2;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
|
@ -2,11 +2,11 @@ package ui;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import Domäne.C3PO;
|
||||||
|
import Domäne.R2D2;
|
||||||
import Domäne.Roboter;
|
import Domäne.Roboter;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class Factory {
|
public class Factory {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
|
@ -55,6 +55,8 @@ public class Factory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void roboterBauen() {
|
private void roboterBauen() {
|
||||||
|
Roboter r = null;
|
||||||
|
int id = 0;
|
||||||
System.out.println("Welchen Robotertyp möchten Sie haben?(R2D2(1) oder C3PO (2)");
|
System.out.println("Welchen Robotertyp möchten Sie haben?(R2D2(1) oder C3PO (2)");
|
||||||
int auswahl = Integer.parseInt(sc.nextLine());
|
int auswahl = Integer.parseInt(sc.nextLine());
|
||||||
|
|
||||||
|
@ -62,15 +64,24 @@ public class Factory {
|
||||||
String name = sc.nextLine();
|
String name = sc.nextLine();
|
||||||
|
|
||||||
if(auswahl == 1) {
|
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) {
|
} else if(auswahl == 2) {
|
||||||
|
id = idVergeben(10000, 19999);
|
||||||
|
r = new C3PO(name, id);
|
||||||
}
|
}
|
||||||
|
roboterLager.put(id, r);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int idVergeben(int min, int max) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue