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,19 +108,22 @@ public class UI {
|
|||
* let the robots sort
|
||||
*/
|
||||
private void useRobot(){
|
||||
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());
|
||||
// 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");
|
||||
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- --- An oder Ausschalten ---");
|
||||
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(" > ");
|
||||
|
@ -126,19 +132,31 @@ public class UI {
|
|||
int input = Integer.parseInt(sc.nextLine());
|
||||
switch (input) {
|
||||
case 1:
|
||||
listAllRobots();
|
||||
fs.searchForRobot(idInput).triggerPowerSwitch();
|
||||
System.out.println("Der Roboter hat seinen Zustand gewechselt");
|
||||
break;
|
||||
case 2:
|
||||
buildNewRobot();
|
||||
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 e) {
|
||||
}catch(NumberFormatException | RobotException 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