From 4ec9407bfe2543116713dce5a3df958f1dfde0c5 Mon Sep 17 00:00:00 2001 From: nikow Date: Thu, 5 Jan 2023 18:32:33 +0100 Subject: [PATCH] Factory hat die methode idVergeben() bekommen. --- Roboterfabrik/src/Domäne/C3PO.java | 8 ++-- Roboterfabrik/src/Domäne/R2D2.java | 8 ++-- Roboterfabrik/src/ui/Factory.java | 63 +++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/Roboterfabrik/src/Domäne/C3PO.java b/Roboterfabrik/src/Domäne/C3PO.java index e964bd7..958df77 100644 --- a/Roboterfabrik/src/Domäne/C3PO.java +++ b/Roboterfabrik/src/Domäne/C3PO.java @@ -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 diff --git a/Roboterfabrik/src/Domäne/R2D2.java b/Roboterfabrik/src/Domäne/R2D2.java index 9c29585..4566db0 100644 --- a/Roboterfabrik/src/Domäne/R2D2.java +++ b/Roboterfabrik/src/Domäne/R2D2.java @@ -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 diff --git a/Roboterfabrik/src/ui/Factory.java b/Roboterfabrik/src/ui/Factory.java index c8955a8..fd8e8af 100644 --- a/Roboterfabrik/src/ui/Factory.java +++ b/Roboterfabrik/src/ui/Factory.java @@ -2,49 +2,76 @@ 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 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(); - + System.out.println("> "); int input = Integer.parseInt(sc.nextLine()); 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; + } -} } \ No newline at end of file