Exceptions abgefangen und eingabemenü für Roboterkontrolle angepasst
parent
b9608f1cdd
commit
56e37abd70
|
@ -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>
|
69
Main.java
69
Main.java
|
@ -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);
|
||||
// }
|
||||
//
|
||||
// */
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue