Factory hat die methode idVergeben() bekommen.

master
nikow 2023-01-05 18:32:33 +01:00
parent 604fe74082
commit 4ec9407bfe
3 changed files with 53 additions and 26 deletions

View File

@ -7,15 +7,15 @@ import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
public class C3PO extends Roboter {
String name;
int id;
static int idZähler = 10000;
//static int idZähler = 10000;
RobotType robotType;
RobotException fehler;
C3PO(String name) {
C3PO(String name, int id) {
super(name);
this.robotType = robotType.C3PO;
this.id = idZähler;
idZähler++;
this.id = id;
//idZähler++;
}
@Override

View File

@ -9,15 +9,15 @@ import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
public class R2D2 extends Roboter {
private int id;
private static int idZähler = 0;
//private static int idZähler = 0;
private RobotType robotType;
RobotException fehler;
R2D2(String name) {
R2D2(String name, int id) {
super(name);
this.robotType = RobotType.R2D2;
this.id = idZähler;
idZähler++;
this.id = id;
//idZähler++;
}
@Override

View File

@ -2,21 +2,27 @@ package ui;
import java.util.Scanner;
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);
public HashMap<Integer, Roboter> roboterLager = new HashMap<>();
public Factory() {
hauptmenü();
}
private void hauptmenü() {
private void hauptmenü() {
mainloop:
while (true) {
mainloop: while (true) {
System.out.println();
System.out.println("========");
System.out.println("Factory Hauptmenü");
System.out.println("0 -> Alle Roboter anzeigen");
System.out.println("1 -> Roboter bauen");
System.out.println("9 -> Beenden");
System.out.println();
@ -26,25 +32,46 @@ private void hauptmenü() {
System.out.println();
try {
switch(input) {
case 1: roboterBauen();
case 9: break mainloop;
}
switch (input) {
case 0:
roboterAnzeigen();
case 1:
roboterBauen();
case 9:
break mainloop;
}
} catch (Exception e) {
}
System.out.println();
}
}
private void roboterAnzeigen() {
}
private void roboterBauen() {
System.out.println("Welchen Robotertyp möchten Sie haben?(R2D2(1) oder C3PO (2)");
int auswahl = Integer.parseInt(sc.nextLine());
System.out.println("Wie wollen Sie ihren Roboter nennen?");
String name = sc.nextLine();
if(auswahl == 1) {
roboterLager.put(idVergeben(0, 9999), R2D2 roboter = new R2D2(name);
} else if(auswahl == 2) {
}
}
}
private void roboterBauen() {
private int idVergeben(int min, int max) {
return 0;
}
}
}