package ui; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import Domäne.C3PO; import Domäne.R2D2; import facade.Factorysystem; import tpe.exceptions.roboter.exceptions.RobotException; public class Factory { Scanner sc = new Scanner(System.in); private Factorysystem factorysystem; public Factory(Factorysystem factorysystem) throws RobotException { this.factorysystem = factorysystem; hauptmenü(); } private void hauptmenü() throws RobotException { 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("2 -> Roboter auswählen"); System.out.println("9 -> Beenden"); System.out.println(); System.out.println("> "); int input = Integer.parseInt(sc.nextLine()); System.out.println(); switch (input) { case 0: roboterAnzeigen(); break; case 1: roboterBauen(); break; case 2: roboterAuswählen(); break; case 9: break mainloop; } 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(); int seriennummer = factorysystem.roboterAnlegen(name, auswahl); System.out.println(name + " mit der Seriennummer: " + seriennummer + " wurde erstellt."); } private void roboterAuswählen() throws RobotException { System.out.println("Geben Sie bitte die Seriennummer ein: "); int id = Integer.parseInt(sc.nextLine()); loop: while (true) { System.out.println("Wählen Sie eine Aktion aus!"); System.out.println("1 -> Zustand abfragen"); System.out.println("2 -> AN/AUS machen"); System.out.println("3 -> Roboter sprechen lassen"); System.out.println("4 -> Letzte Fehlermeldung auslesen"); System.out.println("9 -> Zurück ins Hauptmenü"); System.out.print("> "); int input = Integer.parseInt(sc.nextLine()); switch (input) { case 1: zustandAbfragen(id); break; case 2: schalterBetätigen(id); break; case 3: sprechen(id); break; case 4: letzteFehlermeldung(id); break; case 9: break loop; } } } private void zustandAbfragen(int id) { boolean zustand = factorysystem.zustandRoboter(id); if (zustand == true) { System.out.println("Der Roboter ist an!"); } else if (zustand == false) { System.out.println("Der Roboter ist aus!"); } } private void schalterBetätigen(int id) { boolean zustand = factorysystem.schalterBetätigen(id); if (zustand == true) { System.out.println("Der Roboter wurde eingeschaltet!"); } else if (zustand == false) { System.out.println("Der Roboter wurde abgeschaltet!"); } } private void sprechen(int id) { ArrayList zahlenHinzufügen = new ArrayList<>(); System.out.println("Geben Sie ein Array an!"); System.out.println(); System.out.println("Geben Sie die 1. Zahl an!"); int zahl = Integer.parseInt(sc.nextLine()); zahlenHinzufügen.add(zahl); boolean weiter = true; int i = 2; while (weiter) { System.out.println("Geben Sie die " + i + ". Zahl an"); zahl = Integer.parseInt(sc.nextLine()); zahlenHinzufügen.add(zahl); System.out.println("Möchten Sie weitere Zahl eingeben? (J/N)"); String wahl = sc.nextLine(); if (wahl.equalsIgnoreCase("J")) { i++; weiter = true; } else { weiter = false; int[] zahlen = zahlenHinzufügen.stream().mapToInt(j -> j).toArray(); String ausgabe; try { ausgabe = factorysystem.sprechenAufruf(id, zahlen); System.out.println("Ausgabe: " + ausgabe); } catch (RobotException e) { System.out.println("Fehler! Bitte den letzten Fehler auslesen!"); //e.printStackTrace(); } } } } private void letzteFehlermeldung(int id) { System.out.println (factorysystem.fehlerAuslesen(id)); } }