Merge branch 'master' of https://gitty.informatik.hs-mannheim.de/2122158/PR2-Roboterfabrik.git
commit
4d81d85582
|
@ -1,13 +1,18 @@
|
||||||
package Domäne;
|
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;
|
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);
|
||||||
this.robotType = robotType.C3PO;
|
this.robotType = robotType.C3PO;
|
||||||
this.id = idZähler;
|
this.id = idZähler;
|
||||||
idZähler++;
|
idZähler++;
|
||||||
|
@ -15,26 +20,36 @@ 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;
|
||||||
|
|
||||||
for (int i = 1; i < zahlen.length; i++) {
|
if (isPowerOn() == true) {
|
||||||
remember = zahlen[i];
|
for (int zahl : zahlen) {
|
||||||
int k = i;
|
if (zahl == 42) {
|
||||||
|
fehler = new RobotMagicValueException("Fehler! Zahl 42 im Array!");
|
||||||
while (k > 0 && zahlen[k - 1] < remember) {
|
throw fehler;
|
||||||
zahlen[k] = zahlen[k - 1];
|
}
|
||||||
k--;
|
|
||||||
}
|
}
|
||||||
zahlen[k] = remember;
|
|
||||||
}
|
for (int i = 1; i < zahlen.length; i++) {
|
||||||
return zahlen;
|
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;
|
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,47 +3,55 @@ 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);
|
this.robotType = RobotType.R2D2;
|
||||||
this.robotType = RobotType.R2D2;
|
this.id = idZähler;
|
||||||
this.id = idZähler;
|
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 i = 0; i < zahlen.length - 1; i++) {
|
for (int zahl : zahlen) {
|
||||||
int smallest = i;
|
if (zahl == 42) {
|
||||||
|
fehler = new RobotMagicValueException("Fehler! Zahl 42 im Array!");
|
||||||
for (int k = i+1; k < zahlen.length; k++) {
|
throw fehler;
|
||||||
if (zahlen[i] < zahlen[smallest]) {
|
|
||||||
smallest = k;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remember = zahlen[i];
|
|
||||||
zahlen[i] = zahlen[smallest];
|
for (int i = 0; i < zahlen.length - 1; i++) {
|
||||||
zahlen[smallest] = remember;
|
int smallest = i;
|
||||||
}
|
|
||||||
return zahlen;
|
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
|
@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 {
|
||||||
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) {
|
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