Merge branch 'master' of https://gitty.informatik.hs-mannheim.de/2122158/PR2-Roboterfabrik.git
commit
4d81d85582
|
@ -1,10 +1,15 @@
|
|||
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 {
|
||||
String name;
|
||||
int id;
|
||||
static int idZähler = 10000;
|
||||
RobotType robotType;
|
||||
RobotException fehler;
|
||||
|
||||
C3PO(String name) {
|
||||
super(name);
|
||||
|
@ -15,15 +20,21 @@ public class C3PO extends Roboter{
|
|||
|
||||
@Override
|
||||
public int getId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
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++) {
|
||||
remember = zahlen[i];
|
||||
int k = i;
|
||||
|
@ -35,6 +46,10 @@ public class C3PO extends Roboter{
|
|||
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,13 +3,15 @@ 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;
|
||||
|
||||
RobotException fehler;
|
||||
|
||||
R2D2(String name) {
|
||||
super(name);
|
||||
|
@ -18,10 +20,16 @@ public class R2D2 extends Roboter {
|
|||
idZähler++;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
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++) {
|
||||
int smallest = i;
|
||||
|
@ -36,14 +44,14 @@ public class R2D2 extends Roboter {
|
|||
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 {
|
||||
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