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 infrastructure.Persistenz;
|
||||||
import utility.robot_exceptions.RobotException;
|
import utility.robot_exceptions.RobotException;
|
||||||
|
|
||||||
|
import java.sql.SQLOutput;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODOS:
|
||||||
|
- namen der ROboter abfragen
|
||||||
|
- Seriennummer der Roboter abfragen
|
||||||
|
- Typ der Roboter abfragen
|
||||||
|
*/
|
||||||
public class UI {
|
public class UI {
|
||||||
|
|
||||||
private FactorySystem fs;
|
private FactorySystem fs;
|
||||||
|
@ -22,14 +29,14 @@ public class UI {
|
||||||
}
|
}
|
||||||
public UI (String name){
|
public UI (String name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if(Persistenz.existsSavedData(name)){
|
if(Persistenz.existsSavedData(name)){
|
||||||
try{
|
try{
|
||||||
this.fs = (FactorySystem) Persistenz.loadFactoryData(name);
|
this.fs = (FactorySystem) Persistenz.loadFactoryData(name);
|
||||||
}catch(Exception ignored){
|
}catch(Exception ignored){
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
this.fs = new FactorySystem(name);
|
this.fs = new FactorySystem(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* starting screen
|
* 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");
|
System.out.println("Du hast " + fs.searchForRobot(idInput).getName() + " gewählt der vom Typ " + fs.searchForRobot(idInput).getType() + " ist");
|
||||||
mainloop:
|
mainloop:
|
||||||
while(true) {
|
while(true) {
|
||||||
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: ");
|
||||||
System.out.println("-1- --- Roboter " + (!fs.searchForRobot(idInput).isPowerOn() ? "Einschalten " : "Ausschalten " ) + " ---");
|
System.out.println("-1- --- Roboter " + (!fs.searchForRobot(idInput).isPowerOn() ? "Einschalten " : "Ausschalten " ) + " ---");
|
||||||
System.out.println("-2- -- Sortieren einer Liste --");
|
System.out.println("-2- -- Sortieren einer Liste --");
|
||||||
System.out.println("-3- ---------- Exit -----------");
|
System.out.println("-3- ----- Namen ausgeben ------");
|
||||||
System.out.print(" > ");
|
System.out.println("-4- ------ ID ausgeben --------");
|
||||||
//User options
|
System.out.println("-5- ------ Typ ausgeben -------");
|
||||||
try {
|
System.out.println("-6- ---------- Exit -----------");
|
||||||
int input = Integer.parseInt(sc.nextLine());
|
System.out.print(" > ");
|
||||||
switch (input) {
|
//User options
|
||||||
case 1:
|
try {
|
||||||
fs.searchForRobot(idInput).triggerPowerSwitch();
|
int input = Integer.parseInt(sc.nextLine());
|
||||||
System.out.println("Der Roboter hat seinen Zustand gewechselt");
|
switch (input) {
|
||||||
break;
|
case 1:
|
||||||
case 2:
|
fs.searchForRobot(idInput).triggerPowerSwitch();
|
||||||
int[] unsortedList = null;
|
System.out.println("Der Roboter hat seinen Zustand gewechselt");
|
||||||
while(unsortedList == null) {
|
break;
|
||||||
try {
|
case 2:
|
||||||
unsortedList = fs.searchForRobot(idInput).think(Arrays.stream(sc.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray());
|
int[] unsortedList = null;
|
||||||
System.out.println(fs.searchForRobot(idInput).speak(unsortedList));
|
while(unsortedList == null) {
|
||||||
} catch (NumberFormatException | RobotException e) {
|
try {
|
||||||
if(e.getClass() == RobotException.class){
|
unsortedList = fs.searchForRobot(idInput).think(Arrays.stream(sc.nextLine().split(", ")).mapToInt(Integer::parseInt).toArray());
|
||||||
System.out.println(((RobotException) e).getMessage());
|
System.out.println(fs.searchForRobot(idInput).speak(unsortedList));
|
||||||
break;
|
} catch (NumberFormatException | RobotException e) {
|
||||||
}else{
|
if(e.getClass() == RobotException.class){
|
||||||
System.out.println("Falsches Format versuch es erneut");
|
System.out.println(((RobotException) e).getMessage());
|
||||||
break;
|
break;
|
||||||
}
|
}else{
|
||||||
|
System.out.println("Falsches Format versuch es erneut");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 3: break mainloop;
|
break;
|
||||||
default:
|
case 6: break mainloop;
|
||||||
System.out.println("Keine valide Option"); break;
|
default:
|
||||||
}
|
System.out.println("Keine valide Option"); break;
|
||||||
}catch(NumberFormatException nfe) {
|
|
||||||
System.out.println("Kein valider input");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}catch(NumberFormatException nfe) {
|
||||||
|
System.out.println("Kein valider input");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Es wurden noch keine Roboter erzeugt");
|
System.out.println("Es wurden noch keine Roboter erzeugt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue