From 56e37abd70e1c6bb91627da0709fbf0b2443a7e4 Mon Sep 17 00:00:00 2001 From: Philipp3107 Date: Tue, 10 Jan 2023 02:16:46 +0100 Subject: [PATCH] =?UTF-8?q?Exceptions=20abgefangen=20und=20eingabemen?= =?UTF-8?q?=C3=BC=20f=C3=BCr=20Roboterkontrolle=20angepasst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/runConfigurations.xml | 10 ------ Main.java | 69 ------------------------------------ src/Main.java | 11 ++++++ src/ui/UI.java | 29 ++++++++------- test_factoryFactory.ser | Bin 0 -> 513 bytes 5 files changed, 27 insertions(+), 92 deletions(-) delete mode 100644 .idea/runConfigurations.xml delete mode 100644 Main.java create mode 100644 src/Main.java create mode 100644 test_factoryFactory.ser diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Main.java b/Main.java deleted file mode 100644 index 023cd66..0000000 --- a/Main.java +++ /dev/null @@ -1,69 +0,0 @@ -import src.facade.FactorySystem; -import src.ui.UI; - -public class Main { - public static void main(String[] args) { - FactorySystem fs = new FactorySystem("test_factory"); - - UI ui = new UI(fs); - -// int[] input = {42,6,5,4,3,43,1}; -// int[] input2 = input; -// C3PO Herbert = new C3PO(1, "Herbert"); -// R2D2 Herb = new R2D2(0, "Herb"); -// int[] input3 = {}; -// -// //Herbert.triggerPowerSwitch(); -//// Herb.triggerPowerSwitch(); -// -// -//// try{ -//// String sorted = Herb.speak(input); -//// System.out.println(sorted); -//// } catch (RobotException re) { -//// System.out.println(re); -//// } -// -// try{ -// int[] sorted = Herb.think(input); -// for(int i = 0; i < sorted.length; i++){ -// System.out.print(" " + sorted[i]); -// } -// }catch(RobotException re){ -// re.printStackTrace(); -// } -// -// System.out.println("last exception thrown"); -// String re = Herb.getLastException().toString(); -// System.out.println(re); -// -// Herb.triggerPowerSwitch(); -// -// try{ -// int[] sorted = Herb.think(input); -// for(int i = 0; i < sorted.length; i++){ -// System.out.print(" " + sorted[i]); -// } -// }catch(RobotException e){ -// e.getLocalizedMessage(); -// } -// System.out.println("last exception thrown"); -// re = Herb.getLastException().toString(); -// System.out.println(re); -// -// //System.out.println("Was neues ausgeben"); -// -// //just some testing -// /*C3PO Herbert = new C3PO(0, "Herbert"); -// int[] input = {6,5,4,3,2,1}; -// Herbert.triggerPowerSwitch(); -// try{ -// String asString = Herbert.speak(input); -// System.out.println(asString); -// }catch(RobotException re){ -// System.out.println(re); -// } -// -// */ - } -} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..8d21aa5 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,11 @@ +import facade.FactorySystem; +import ui.UI; + +public class Main { + public static void main(String[] args) { + FactorySystem fs = new FactorySystem("test_factory"); + + UI ui = new UI(fs); + } + +} diff --git a/src/ui/UI.java b/src/ui/UI.java index 217f5ce..b449158 100644 --- a/src/ui/UI.java +++ b/src/ui/UI.java @@ -120,10 +120,7 @@ public class UI { 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("-1- --- Roboter " + (!fs.searchForRobot(idInput).isPowerOn() ? "Einschalten " : "Ausschalten " ) + " ---"); System.out.println("-2- -- Sortieren einer Liste --"); System.out.println("-3- ---------- Exit -----------"); System.out.print(" > "); @@ -140,21 +137,27 @@ public class UI { 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)); + } catch (NumberFormatException | RobotException e) { + if(e.getClass() == RobotException.class){ + System.out.println(((RobotException) e).getMessage()); + break; + }else{ + System.out.println("Falsches Format versuch es erneut"); + break; + } } } - System.out.println(fs.searchForRobot(idInput).speak(unsortedList)); - break; - case 3: break; + case 3: break mainloop; default: - System.out.println("Keine valide Option auswahl"); break; + System.out.println("Keine valide Option"); break; } - }catch(NumberFormatException | RobotException e) { - System.out.println("Kein valider Input"); + }catch(NumberFormatException nfe) { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..4972145d17aefffcc54a3a682f4eee0c8e796fb3 GIT binary patch literal 513 zcmYk2&r1S99L2w`Za-8+4ZL;s5V&BMz@QE)E^HpOQ$aPlgKn)m%j~EtNMMH&y4F3S zpo7=`fauVriyb>fr!JklHZy9uFgwG1zPx$wjlMzkD8x+CLY9*$qB+RU=G67rfm$j$jK$S75Edgk<-ZN4#N#hlb<(t zKZA=61p+##9b~t$Pa!TJm2>5GtA^?M=z2AB^>L{H2zTi?7mG|2SF-u+*XF_5Yic+Y zoI-R)L`b-Q?2dco69rTq6wBNL)g@g_4G3euj$LLEhZnJCh>RBNX|kHbf2I{?V^!WP zYT%p!AqTZEgXE+=VN|O!YB>$TSkIMg;zFwk7rXpU7MqTP%Rnt*TC+}h(s`?5NVdj* UNtq<}Uqr!ax8@;N35n?bF9fQeh5!Hn literal 0 HcmV?d00001