Exceptions RobotMagicValue erweitert und implementiert, getLastException
implementiertmaster
parent
d5070e89cf
commit
5a78ea1429
|
@ -1,10 +1,15 @@
|
||||||
package Domäne;
|
package Domäne;
|
||||||
|
|
||||||
|
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||||
|
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||||
|
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||||
|
|
||||||
public class C3PO extends Roboter {
|
public class C3PO extends Roboter {
|
||||||
String name;
|
String name;
|
||||||
int id;
|
int id;
|
||||||
static int idZähler = 10000;
|
static int idZähler = 10000;
|
||||||
RobotType robotType;
|
RobotType robotType;
|
||||||
|
RobotException fehler;
|
||||||
|
|
||||||
C3PO(String name) {
|
C3PO(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -15,15 +20,21 @@ public class C3PO extends Roboter{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
// TODO Auto-generated method stub
|
return id;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] think(int[] zahlen) throws RobotException {
|
public int[] think(int[] zahlen) throws RobotException {
|
||||||
int remember;
|
int remember;
|
||||||
|
|
||||||
|
if (isPowerOn() == true) {
|
||||||
|
for (int zahl : zahlen) {
|
||||||
|
if (zahl == 42) {
|
||||||
|
fehler = new RobotMagicValueException("Fehler! Zahl 42 im Array!");
|
||||||
|
throw fehler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 1; i < zahlen.length; i++) {
|
for (int i = 1; i < zahlen.length; i++) {
|
||||||
remember = zahlen[i];
|
remember = zahlen[i];
|
||||||
int k = i;
|
int k = i;
|
||||||
|
@ -35,6 +46,10 @@ public class C3PO extends Roboter{
|
||||||
zahlen[k] = remember;
|
zahlen[k] = remember;
|
||||||
}
|
}
|
||||||
return zahlen;
|
return zahlen;
|
||||||
|
} else
|
||||||
|
fehler = new RobotIllegalStateException("Roboter ausgeschaltet! Bitte einschalten.");
|
||||||
|
throw fehler;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ public class Nexus6 extends Roboter {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
int id;
|
int id;
|
||||||
|
RobotException fehler;
|
||||||
private static Nexus6 PRIS;
|
private static Nexus6 PRIS;
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,14 +41,16 @@ public class Nexus6 extends Roboter {
|
||||||
//Methode soll Fehler ausgeben, da der Roboter nicht Funktioniert.
|
//Methode soll Fehler ausgeben, da der Roboter nicht Funktioniert.
|
||||||
@Override
|
@Override
|
||||||
public String speak(int[] zahlen) throws RobotException {
|
public String speak(int[] zahlen) throws RobotException {
|
||||||
throw new RobotIllegalStateException ("Roboter ausgeschaltet und Defekt!");
|
fehler = new RobotIllegalStateException ("Roboter ausgeschaltet und Defekt!");
|
||||||
|
throw fehler;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Methode soll Fehler ausgeben, da der Roboter nicht Funktioniert.
|
//Methode soll Fehler ausgeben, da der Roboter nicht Funktioniert.
|
||||||
@Override
|
@Override
|
||||||
public int[] think(int[] zahlen) throws RobotException {
|
public int[] think(int[] zahlen) throws RobotException {
|
||||||
throw new RobotIllegalStateException ("Roboter ausgeschaltet und Defekt!");
|
fehler = new RobotIllegalStateException ("Roboter ausgeschaltet und Defekt!");
|
||||||
|
throw fehler;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,15 @@ package Domäne;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import tpe.exceptions.roboter.Robot;
|
import tpe.exceptions.roboter.Robot;
|
||||||
import tpe.exceptions.roboter.RobotException;
|
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||||
|
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||||
|
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||||
|
|
||||||
public class R2D2 extends Roboter {
|
public class R2D2 extends Roboter {
|
||||||
private int id;
|
private int id;
|
||||||
private static int idZähler = 0;
|
private static int idZähler = 0;
|
||||||
private RobotType robotType;
|
private RobotType robotType;
|
||||||
|
RobotException fehler;
|
||||||
|
|
||||||
R2D2(String name) {
|
R2D2(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -18,10 +20,16 @@ public class R2D2 extends Roboter {
|
||||||
idZähler++;
|
idZähler++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] think(int[] zahlen) throws RobotException {
|
public int[] think(int[] zahlen) throws RobotException {
|
||||||
int remember;
|
int remember;
|
||||||
|
if (isPowerOn() == true) {
|
||||||
|
for (int zahl : zahlen) {
|
||||||
|
if (zahl == 42) {
|
||||||
|
fehler = new RobotMagicValueException("Fehler! Zahl 42 im Array!");
|
||||||
|
throw fehler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < zahlen.length - 1; i++) {
|
for (int i = 0; i < zahlen.length - 1; i++) {
|
||||||
int smallest = i;
|
int smallest = i;
|
||||||
|
@ -36,14 +44,14 @@ public class R2D2 extends Roboter {
|
||||||
zahlen[smallest] = remember;
|
zahlen[smallest] = remember;
|
||||||
}
|
}
|
||||||
return zahlen;
|
return zahlen;
|
||||||
|
} else
|
||||||
|
fehler = new RobotIllegalStateException("Roboter ausgeschaltet! Bitte einschalten.");
|
||||||
|
throw fehler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
// TODO Auto-generated method stub
|
return id;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,14 @@ import java.util.stream.IntStream;
|
||||||
|
|
||||||
import tpe.exceptions.roboter.Robot;
|
import tpe.exceptions.roboter.Robot;
|
||||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||||
|
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
||||||
|
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||||
|
|
||||||
public abstract class Roboter implements Robot {
|
public abstract class Roboter implements Robot {
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
boolean power;
|
boolean power;
|
||||||
|
RobotException fehler;
|
||||||
|
|
||||||
// Roboter wird in einem ausgeschalteten Zustand instanziiert!
|
// Roboter wird in einem ausgeschalteten Zustand instanziiert!
|
||||||
|
|
||||||
|
@ -53,12 +56,22 @@ public abstract class Roboter implements Robot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RobotException getLastException() {
|
public RobotException getLastException() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return fehler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String speak(int[] zahlen) throws RobotException {
|
public String speak(int[] zahlen) throws RobotException {
|
||||||
|
if (isPowerOn() == true) {
|
||||||
|
for (int zahl : zahlen) {
|
||||||
|
if (zahl == 42) {
|
||||||
|
fehler = new RobotMagicValueException("Fehler! Zahl 42 im Array!");
|
||||||
|
throw fehler;
|
||||||
|
}
|
||||||
|
}
|
||||||
return prepare(zahlen);
|
return prepare(zahlen);
|
||||||
|
} else
|
||||||
|
fehler = new RobotIllegalStateException("Roboter ausgeschaltet! Bitte einschalten.");
|
||||||
|
throw fehler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String prepare(int[] zahlen) {
|
private String prepare(int[] zahlen) {
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package tpe.exceptions.roboter.exceptions;
|
||||||
|
|
||||||
|
public class RobotMagicValueException extends RobotException {
|
||||||
|
|
||||||
|
public RobotMagicValueException (String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue