Weitere Methoden in Factory, Factorysystem, RobotFactory. Main erstellt!
parent
04c6dc90f1
commit
eeda064427
|
@ -5,10 +5,10 @@ import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
|||
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||
|
||||
public class C3PO extends Roboter {
|
||||
String name;
|
||||
int id;
|
||||
private String name;
|
||||
private int id;
|
||||
//static int idZähler = 10000;
|
||||
RobotType robotType;
|
||||
private RobotType robotType;
|
||||
RobotException fehler;
|
||||
|
||||
public C3PO(String name, int id) {
|
||||
|
|
|
@ -44,4 +44,16 @@ public RobotFactory (String name) {
|
|||
|
||||
return randomValue;
|
||||
}
|
||||
|
||||
public boolean roboterZustand(int id) {
|
||||
Roboter r = findeRoboter(id);
|
||||
boolean zustand = r.isPowerOn();
|
||||
return zustand;
|
||||
}
|
||||
public boolean schalterAnAus(int id){
|
||||
Roboter r = findeRoboter(id);
|
||||
r.triggerPowerSwitch();
|
||||
boolean zustand = r.isPowerOn();
|
||||
return zustand;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,5 +31,13 @@ public class Factorysystem {
|
|||
|
||||
}
|
||||
|
||||
public boolean zustandRoboter (int id) {
|
||||
return robotFactory.roboterZustand(id);
|
||||
}
|
||||
|
||||
public boolean schalterBetätigen(int id) {
|
||||
return robotFactory.schalterAnAus(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package main;
|
||||
|
||||
import facade.Factorysystem;
|
||||
import ui.Factory;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Factorysystem fs = new Factorysystem ("Robot Fabrik");
|
||||
Factory ui = new Factory (fs);
|
||||
}
|
||||
|
||||
}
|
|
@ -6,13 +6,10 @@ import Domäne.C3PO;
|
|||
import Domäne.R2D2;
|
||||
import facade.Factorysystem;
|
||||
|
||||
|
||||
|
||||
public class Factory {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
private Factorysystem factorysystem;
|
||||
|
||||
|
||||
public Factory(Factorysystem factorysystem) {
|
||||
this.factorysystem = factorysystem;
|
||||
hauptmenü();
|
||||
|
@ -26,6 +23,7 @@ public class Factory {
|
|||
System.out.println("Factory Hauptmenü");
|
||||
System.out.println("0 -> Alle Roboter anzeigen");
|
||||
System.out.println("1 -> Roboter bauen");
|
||||
System.out.println("2 -> Roboter auswählen");
|
||||
System.out.println("9 -> Beenden");
|
||||
System.out.println();
|
||||
|
||||
|
@ -37,8 +35,13 @@ public class Factory {
|
|||
switch (input) {
|
||||
case 0:
|
||||
roboterAnzeigen();
|
||||
break;
|
||||
case 1:
|
||||
roboterBauen();
|
||||
break;
|
||||
case 2:
|
||||
roboterAuswählen();
|
||||
break;
|
||||
case 9:
|
||||
break mainloop;
|
||||
}
|
||||
|
@ -66,13 +69,54 @@ public class Factory {
|
|||
int seriennummer = factorysystem.roboterAnlegen(name, auswahl);
|
||||
System.out.println(name + " mit der Seriennummer: " + seriennummer + " wurde erstellt.");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void roboterAuswählen() {
|
||||
System.out.println("Geben Sie bitte die Seriennummer ein: ");
|
||||
int id = Integer.parseInt(sc.nextLine());
|
||||
|
||||
loop: while (true) {
|
||||
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("9 -> Zurück ins Hauptmenü");
|
||||
System.out.print("> ");
|
||||
int input = Integer.parseInt(sc.nextLine());
|
||||
|
||||
try {
|
||||
switch (input) {
|
||||
case 1:
|
||||
zustandAbfragen(id);
|
||||
break;
|
||||
case 2:
|
||||
schalterBetätigen(id);
|
||||
break;
|
||||
case 9:
|
||||
break loop;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void zustandAbfragen(int id) {
|
||||
boolean zustand = factorysystem.zustandRoboter(id);
|
||||
if (zustand == true) {
|
||||
System.out.println("Der Roboter ist an!");
|
||||
} else if (zustand == false) {
|
||||
System.out.println("Der Roboter ist aus!");
|
||||
}
|
||||
}
|
||||
|
||||
private void schalterBetätigen(int id) {
|
||||
boolean zustand = factorysystem.schalterBetätigen(id);
|
||||
if (zustand == true) {
|
||||
System.out.println("Der Roboter wurde eingeschaltet!");
|
||||
} else if (zustand == false) {
|
||||
System.out.println("Der Roboter wurde abgeschaltet!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue