Exceptions abgefangen und eingabemenü für Roboterkontrolle angepasst

main
Philipp3107 2023-01-10 02:16:46 +01:00
parent b9608f1cdd
commit 56e37abd70
5 changed files with 27 additions and 92 deletions

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -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);
// }
//
// */
}
}

11
src/Main.java 100644
View File

@ -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);
}
}

View File

@ -120,10 +120,7 @@ public class UI {
System.out.println(); System.out.println();
System.out.println("_______________________________"); System.out.println("_______________________________");
System.out.println("Sie haben folgende optionen: "); System.out.println("Sie haben folgende optionen: ");
if(fs.searchForRobot(idInput).isPowerOn()) System.out.println("-1- --- Roboter " + (!fs.searchForRobot(idInput).isPowerOn() ? "Einschalten " : "Ausschalten " ) + " ---");
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("-2- -- Sortieren einer Liste --");
System.out.println("-3- ---------- Exit -----------"); System.out.println("-3- ---------- Exit -----------");
System.out.print(" > "); System.out.print(" > ");
@ -140,19 +137,25 @@ public class UI {
while(unsortedList == null) { while(unsortedList == null) {
try { try {
unsortedList = fs.searchForRobot(idInput).think(Arrays.stream(sc.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray()); 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)); 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) { } catch (NumberFormatException | RobotException e) {
System.out.println("Kein valider Input"); if(e.getClass() == RobotException.class){
System.out.println(((RobotException) e).getMessage());
break;
}else{
System.out.println("Falsches Format versuch es erneut");
break;
}
}
}
break;
case 3: break mainloop;
default:
System.out.println("Keine valide Option"); break;
}
}catch(NumberFormatException nfe) {
System.out.println("Kein valider input");
} }
} }
} else { } else {

Binary file not shown.