Weitere UI Erweiterungen. Neue Methoden.
parent
eeda064427
commit
cc7bc20b1d
|
@ -2,6 +2,8 @@ package Domäne;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
|
||||
public class RobotFactory {
|
||||
private String name;
|
||||
private HashMap <Integer, Roboter> roboterLager = new HashMap<>();
|
||||
|
@ -56,4 +58,12 @@ public RobotFactory (String name) {
|
|||
boolean zustand = r.isPowerOn();
|
||||
return zustand;
|
||||
}
|
||||
|
||||
public String aufrufSpeakAndThink (int id, int [] zahlen) throws RobotException {
|
||||
Roboter r = findeRoboter(id);
|
||||
int [] sotiert = r.think(zahlen);
|
||||
String ausgabe = r.speak(sotiert);
|
||||
return ausgabe;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import Domäne.R2D2;
|
|||
import Domäne.RobotFactory;
|
||||
import Domäne.RobotType;
|
||||
import Domäne.Roboter;
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
|
||||
public class Factorysystem {
|
||||
private RobotFactory robotFactory;
|
||||
|
@ -39,5 +40,10 @@ public class Factorysystem {
|
|||
return robotFactory.schalterAnAus(id);
|
||||
}
|
||||
|
||||
public String sprechenAufruf(int id, int[] zahlen) throws RobotException {
|
||||
String ausgabe = robotFactory.aufrufSpeakAndThink(id, zahlen);
|
||||
return ausgabe;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package main;
|
||||
|
||||
import facade.Factorysystem;
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
import ui.Factory;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws RobotException {
|
||||
Factorysystem fs = new Factorysystem ("Robot Fabrik");
|
||||
Factory ui = new Factory (fs);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
package ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
import Domäne.C3PO;
|
||||
import Domäne.R2D2;
|
||||
import facade.Factorysystem;
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
|
||||
public class Factory {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
private Factorysystem factorysystem;
|
||||
|
||||
public Factory(Factorysystem factorysystem) {
|
||||
public Factory(Factorysystem factorysystem) throws RobotException {
|
||||
this.factorysystem = factorysystem;
|
||||
hauptmenü();
|
||||
}
|
||||
|
||||
private void hauptmenü() {
|
||||
private void hauptmenü() throws RobotException {
|
||||
|
||||
mainloop: while (true) {
|
||||
System.out.println();
|
||||
|
@ -31,7 +34,7 @@ public class Factory {
|
|||
int input = Integer.parseInt(sc.nextLine());
|
||||
System.out.println();
|
||||
|
||||
try {
|
||||
|
||||
switch (input) {
|
||||
case 0:
|
||||
roboterAnzeigen();
|
||||
|
@ -44,11 +47,9 @@ public class Factory {
|
|||
break;
|
||||
case 9:
|
||||
break mainloop;
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
}
|
||||
|
@ -71,7 +72,7 @@ public class Factory {
|
|||
|
||||
}
|
||||
|
||||
private void roboterAuswählen() {
|
||||
private void roboterAuswählen() throws RobotException {
|
||||
System.out.println("Geben Sie bitte die Seriennummer ein: ");
|
||||
int id = Integer.parseInt(sc.nextLine());
|
||||
|
||||
|
@ -79,11 +80,12 @@ public class Factory {
|
|||
System.out.println("Wählen Sie eine Aktion aus!");
|
||||
System.out.println("1 -> Zustand abfragen");
|
||||
System.out.println("2 -> AN/AUS machen");
|
||||
System.out.println("3 -> Roboter sprechen lassen");
|
||||
System.out.println("9 -> Zurück ins Hauptmenü");
|
||||
System.out.print("> ");
|
||||
int input = Integer.parseInt(sc.nextLine());
|
||||
|
||||
try {
|
||||
|
||||
switch (input) {
|
||||
case 1:
|
||||
zustandAbfragen(id);
|
||||
|
@ -91,13 +93,14 @@ public class Factory {
|
|||
case 2:
|
||||
schalterBetätigen(id);
|
||||
break;
|
||||
case 3:
|
||||
sprechen(id);
|
||||
break;
|
||||
case 9:
|
||||
break loop;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,4 +122,36 @@ public class Factory {
|
|||
}
|
||||
}
|
||||
|
||||
private void sprechen(int id) throws RobotException {
|
||||
ArrayList <Integer> zahlenHinzufügen = new ArrayList<>();
|
||||
System.out.println("Geben Sie ein Array an!");
|
||||
System.out.println();
|
||||
System.out.println("Geben Sie die 1. Zahl an!");
|
||||
int zahl = Integer.parseInt(sc.nextLine());
|
||||
zahlenHinzufügen.add(zahl);
|
||||
boolean weiter = true;
|
||||
int i = 2;
|
||||
while (weiter) {
|
||||
|
||||
System.out.println("Geben Sie die " + i + ". Zahl an");
|
||||
zahl = Integer.parseInt(sc.nextLine());
|
||||
zahlenHinzufügen.add(zahl);
|
||||
System.out.println("Möchten Sie weitere Zahl eingeben? (J/N)");
|
||||
String wahl = sc.nextLine();
|
||||
if (wahl.equalsIgnoreCase("J")) {
|
||||
i++;
|
||||
weiter = true;
|
||||
} else {
|
||||
weiter = false;
|
||||
int[] zahlen = zahlenHinzufügen.stream().mapToInt(j -> j).toArray();
|
||||
|
||||
String ausgabe = factorysystem.sprechenAufruf(id, zahlen);
|
||||
System.out.println("Ausgabe: " + ausgabe);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue