Die Ersten Exceptions erstellt und in Nexus6 Klasse (singleton) in
think() und speak() eingefügt.master
parent
a12278c48b
commit
eeaa28e263
|
@ -1,13 +1,13 @@
|
|||
package Domäne;
|
||||
|
||||
import Exception.RobotException;
|
||||
import Exception.RobotIllegalStateException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||
|
||||
public class Nexus6 extends Roboter {
|
||||
|
||||
String name;
|
||||
int id;
|
||||
private static Nexus6 pris;
|
||||
private static Nexus6 PRIS;
|
||||
|
||||
|
||||
private Nexus6() {
|
||||
|
@ -20,10 +20,11 @@ public class Nexus6 extends Roboter {
|
|||
|
||||
|
||||
public static Nexus6 getInstance () {
|
||||
if (pris == null) {
|
||||
pris = new Nexus6();
|
||||
if (PRIS == null) {
|
||||
PRIS = new Nexus6();
|
||||
|
||||
}
|
||||
return pris;
|
||||
return PRIS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,12 +37,19 @@ public class Nexus6 extends Roboter {
|
|||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
//Methode soll Fehler ausgeben, da der Roboter nicht Funktioniert.
|
||||
@Override
|
||||
public int[] think(int[] zahlen)throws RobotException {
|
||||
public String speak(int[] zahlen) throws RobotException {
|
||||
throw new RobotIllegalStateException ("Roboter ausgeschaltet und Defekt!");
|
||||
|
||||
}
|
||||
|
||||
//Methode soll Fehler ausgeben, da der Roboter nicht Funktioniert.
|
||||
@Override
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
throw new RobotIllegalStateException ("Roboter ausgeschaltet und Defekt!");
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,16 +10,16 @@ public RobotFactory (String name) {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public int addRobot (RobotType robotType) {
|
||||
public int addRobot (RobotType robotType, String name) {
|
||||
Roboter roboter;
|
||||
|
||||
if (RobotType.R2D2 == robotType) {
|
||||
roboter = new R2D2 ("R2D2");
|
||||
roboter = new R2D2 (name);
|
||||
roboters.put(roboter.getId(), roboter);
|
||||
return roboter.getId();
|
||||
}
|
||||
else if (RobotType.C3PO == robotType) {
|
||||
roboter = new C3PO ("C3PO");
|
||||
roboter = new C3PO (name);
|
||||
roboters.put(roboter.getId(), roboter);
|
||||
return roboter.getId();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package Domäne;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import tpe.exceptions.roboter.Robot;
|
||||
import tpe.exceptions.roboter.RobotException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
|
||||
public abstract class Roboter implements Robot {
|
||||
|
||||
|
@ -66,6 +66,7 @@ public abstract class Roboter implements Robot {
|
|||
Stream.of(zahlen).forEach(n -> ausgabe = ausgabe + n + ";");
|
||||
return ausgabe;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package tpe.exceptions.roboter;
|
||||
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||
|
||||
/**
|
||||
* Das Interface repräsentiert einen einfachen Roboter mit seinen Funktionen.
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package tpe.exceptions.roboter.exceptions;
|
||||
|
||||
public class RobotException extends Exception {
|
||||
|
||||
public RobotException (String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package tpe.exceptions.roboter.exceptions;
|
||||
|
||||
public class RobotIllegalStateException extends RobotException {
|
||||
|
||||
public RobotIllegalStateException (String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue