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 { public class C3PO extends Roboter {
String name; String name;
int id; int id;
static int idZähler = 10000; //static int idZähler = 10000;
RobotType robotType; RobotType robotType;
RobotException fehler; RobotException fehler;
C3PO(String name) { C3PO(String name, int id) {
super(name); super(name);
this.robotType = robotType.C3PO; this.robotType = robotType.C3PO;
this.id = idZähler; this.id = id;
idZähler++; //idZähler++;
} }
@Override @Override

View File

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

View File

@ -2,21 +2,27 @@ package ui;
import java.util.Scanner; import java.util.Scanner;
import Domäne.Roboter;
import java.util.Collection;
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);
public HashMap<Integer, Roboter> roboterLager = new HashMap<>();
public Factory() { public Factory() {
hauptmenü(); hauptmenü();
} }
private void hauptmenü() { private void hauptmenü() {
mainloop: mainloop: while (true) {
while (true) {
System.out.println(); System.out.println();
System.out.println("========"); System.out.println("========");
System.out.println("Factory Hauptmenü"); System.out.println("Factory Hauptmenü");
System.out.println("0 -> Alle Roboter anzeigen");
System.out.println("1 -> Roboter bauen"); System.out.println("1 -> Roboter bauen");
System.out.println("9 -> Beenden"); System.out.println("9 -> Beenden");
System.out.println(); System.out.println();
@ -27,8 +33,12 @@ private void hauptmenü() {
try { try {
switch (input) { switch (input) {
case 1: roboterBauen(); case 0:
case 9: break mainloop; roboterAnzeigen();
case 1:
roboterBauen();
case 9:
break mainloop;
} }
} catch (Exception e) { } catch (Exception e) {
@ -36,15 +46,32 @@ private void hauptmenü() {
} }
System.out.println(); System.out.println();
} }
} }
private void roboterAnzeigen() {
}
private void roboterBauen() { 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 int idVergeben(int min, int max) {
return 0;
}
}