updated Auswahlmenü für Roboterkontrolle
parent
56e37abd70
commit
0f4c343fce
104
src/ui/UI.java
104
src/ui/UI.java
|
@ -6,9 +6,16 @@ import facade.FactorySystem;
|
|||
import infrastructure.Persistenz;
|
||||
import utility.robot_exceptions.RobotException;
|
||||
|
||||
import java.sql.SQLOutput;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
/*
|
||||
TODOS:
|
||||
- namen der ROboter abfragen
|
||||
- Seriennummer der Roboter abfragen
|
||||
- Typ der Roboter abfragen
|
||||
*/
|
||||
public class UI {
|
||||
|
||||
private FactorySystem fs;
|
||||
|
@ -22,14 +29,14 @@ public class UI {
|
|||
}
|
||||
public UI (String name){
|
||||
this.name = name;
|
||||
if(Persistenz.existsSavedData(name)){
|
||||
try{
|
||||
this.fs = (FactorySystem) Persistenz.loadFactoryData(name);
|
||||
}catch(Exception ignored){
|
||||
}
|
||||
}else{
|
||||
this.fs = new FactorySystem(name);
|
||||
}
|
||||
if(Persistenz.existsSavedData(name)){
|
||||
try{
|
||||
this.fs = (FactorySystem) Persistenz.loadFactoryData(name);
|
||||
}catch(Exception ignored){
|
||||
}
|
||||
}else{
|
||||
this.fs = new FactorySystem(name);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* starting screen
|
||||
|
@ -117,49 +124,52 @@ public class UI {
|
|||
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: ");
|
||||
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(" > ");
|
||||
//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());
|
||||
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();
|
||||
System.out.println("_______________________________");
|
||||
System.out.println("Sie haben folgende optionen: ");
|
||||
System.out.println("-1- --- Roboter " + (!fs.searchForRobot(idInput).isPowerOn() ? "Einschalten " : "Ausschalten " ) + " ---");
|
||||
System.out.println("-2- -- Sortieren einer Liste --");
|
||||
System.out.println("-3- ----- Namen ausgeben ------");
|
||||
System.out.println("-4- ------ ID ausgeben --------");
|
||||
System.out.println("-5- ------ Typ ausgeben -------");
|
||||
System.out.println("-6- ---------- 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());
|
||||
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;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3: break mainloop;
|
||||
default:
|
||||
System.out.println("Keine valide Option"); break;
|
||||
}
|
||||
}catch(NumberFormatException nfe) {
|
||||
System.out.println("Kein valider input");
|
||||
|
||||
}
|
||||
break;
|
||||
case 6: break mainloop;
|
||||
default:
|
||||
System.out.println("Keine valide Option"); break;
|
||||
}
|
||||
}catch(NumberFormatException nfe) {
|
||||
System.out.println("Kein valider input");
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("Es wurden noch keine Roboter erzeugt");
|
||||
} else {
|
||||
System.out.println("Es wurden noch keine Roboter erzeugt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue