From 683e5d990958559150582360e83b37330ae83e10 Mon Sep 17 00:00:00 2001 From: CedricNew Date: Tue, 10 Jan 2023 01:41:34 +0100 Subject: [PATCH] Expansion of the UI class --- src/ui/UI.java | 82 ++++++++++++++++++++++++---------------- test_factoryFactory.ser | Bin 434 -> 0 bytes 2 files changed, 50 insertions(+), 32 deletions(-) delete mode 100644 test_factoryFactory.ser diff --git a/src/ui/UI.java b/src/ui/UI.java index 544f3bc..217f5ce 100644 --- a/src/ui/UI.java +++ b/src/ui/UI.java @@ -4,6 +4,9 @@ import domain.Robot; import domain.RobotType; import facade.FactorySystem; import infrastructure.Persistenz; +import utility.robot_exceptions.RobotException; + +import java.util.Arrays; import java.util.Scanner; public class UI { @@ -105,40 +108,55 @@ public class UI { * let the robots sort */ private void useRobot(){ - System.out.println("Welchen Roboter wollen Sie verwenden"); - listAllRobots(); - System.out.print(" ID > "); - int idInput = Integer.parseInt(sc.nextLine()); - // Change the searchForRobot Methode (safety) - Robot r = fs.searchForRobot(idInput); - System.out.println("Du hast " + r.getName() + " gewählt der vom Typ " + r.getType() + " ist"); - mainloop: - while(true) { - System.out.println(); - System.out.println("_______________________________"); - System.out.println("Sie haben folgende optionen: "); - System.out.println("-1- --- An oder Ausschalten ---"); - System.out.println("-2- -- Sortieren einer Liste --"); - System.out.println("-3- ---------- Exit -----------"); - System.out.print(" > "); - //User options - try { - int input = Integer.parseInt(sc.nextLine()); - switch (input) { - case 1: - listAllRobots(); - break; - case 2: - buildNewRobot(); - break; - case 3: - break; - default: - System.out.println("Keine valide Option auswahl"); break; + String[] listOfAll = fs.getAllRobots(); + if(listOfAll.length > 0){ + System.out.println("Welchen Roboter wollen Sie verwenden"); + listAllRobots(); + System.out.print(" ID > "); + int idInput = Integer.parseInt(sc.nextLine()); + System.out.println("Du hast " + fs.searchForRobot(idInput).getName() + " gewählt der vom Typ " + fs.searchForRobot(idInput).getType() + " ist"); + mainloop: + while(true) { + System.out.println(); + System.out.println("_______________________________"); + System.out.println("Sie haben folgende optionen: "); + if(fs.searchForRobot(idInput).isPowerOn()) + System.out.println("-1- --- Roboter Ausschalten ---"); + if(!fs.searchForRobot(idInput).isPowerOn()) + System.out.println("-1- --- Roboter Ausschalten ---"); + System.out.println("-2- -- Sortieren einer Liste --"); + System.out.println("-3- ---------- Exit -----------"); + System.out.print(" > "); + //User options + try { + int input = Integer.parseInt(sc.nextLine()); + switch (input) { + case 1: + fs.searchForRobot(idInput).triggerPowerSwitch(); + System.out.println("Der Roboter hat seinen Zustand gewechselt"); + break; + case 2: + int[] unsortedList = null; + while(unsortedList == null) { + try { + unsortedList = fs.searchForRobot(idInput).think(Arrays.stream(sc.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray()); + } catch (NumberFormatException nFE) { + System.out.println("Falsches Format versuch es erneut"); + } + } + System.out.println(fs.searchForRobot(idInput).speak(unsortedList)); + break; + case 3: + break; + default: + System.out.println("Keine valide Option auswahl"); break; + } + }catch(NumberFormatException | RobotException e) { + System.out.println("Kein valider Input"); } - }catch(NumberFormatException e) { - System.out.println("Kein valider Input"); } + } else { + System.out.println("Es wurden noch keine Roboter erzeugt"); } } } diff --git a/test_factoryFactory.ser b/test_factoryFactory.ser deleted file mode 100644 index 05a917043056cf50f82d5af30ce15e598a5d6060..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 434 zcmZ4UmVvdnh=DI9KQ}QmPtPqexg@`+a@LKDa!TEHR!j`co(ycs#s&GFEuGBYr_F>vMNC#FE`^km>H$tX%K&dAS6sVJ~_0Gq*6&H!X~cij95npNWO@H2POmZ=K%vk+Xv*w%#uodaL~jf