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