Expansion of the UI class
parent
08418fa66c
commit
683e5d9909
|
@ -4,6 +4,9 @@ import domain.Robot;
|
|||
import domain.RobotType;
|
||||
import facade.FactorySystem;
|
||||
import infrastructure.Persistenz;
|
||||
import utility.robot_exceptions.RobotException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class UI {
|
||||
|
@ -105,40 +108,55 @@ public class UI {
|
|||
* let the robots sort
|
||||
*/
|
||||
private void useRobot(){
|
||||
System.out.println("Welchen Roboter wollen Sie verwenden");
|
||||
listAllRobots();
|
||||
System.out.print(" ID > ");
|
||||
int idInput = Integer.parseInt(sc.nextLine());
|
||||
// Change the searchForRobot Methode (safety)
|
||||
Robot r = fs.searchForRobot(idInput);
|
||||
System.out.println("Du hast " + r.getName() + " gewählt der vom Typ " + r.getType() + " ist");
|
||||
mainloop:
|
||||
while(true) {
|
||||
System.out.println();
|
||||
System.out.println("_______________________________");
|
||||
System.out.println("Sie haben folgende optionen: ");
|
||||
System.out.println("-1- --- An oder 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:
|
||||
listAllRobots();
|
||||
break;
|
||||
case 2:
|
||||
buildNewRobot();
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
System.out.println("Keine valide Option auswahl"); break;
|
||||
String[] listOfAll = fs.getAllRobots();
|
||||
if(listOfAll.length > 0){
|
||||
System.out.println("Welchen Roboter wollen Sie verwenden");
|
||||
listAllRobots();
|
||||
System.out.print(" ID > ");
|
||||
int idInput = Integer.parseInt(sc.nextLine());
|
||||
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: ");
|
||||
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("-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());
|
||||
} catch (NumberFormatException nFE) {
|
||||
System.out.println("Falsches Format versuch es erneut");
|
||||
}
|
||||
}
|
||||
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) {
|
||||
System.out.println("Kein valider Input");
|
||||
}
|
||||
}catch(NumberFormatException e) {
|
||||
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