Roboterklasse Speak Methode mit Stream und Lambda implementiert
parent
c9805dbd38
commit
a39552dc43
|
@ -6,9 +6,9 @@ import tpe.exceptions.roboter.Robot;
|
|||
import tpe.exceptions.roboter.RobotException;
|
||||
|
||||
public class R2D2 extends Roboter {
|
||||
int id;
|
||||
static int idZähler = 0;
|
||||
RobotType robotType;
|
||||
private int id;
|
||||
private static int idZähler = 0;
|
||||
private RobotType robotType;
|
||||
|
||||
|
||||
R2D2 (String name){
|
||||
|
@ -18,14 +18,6 @@ public class R2D2 extends Roboter {
|
|||
idZähler++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String speak(int[] zahlen) throws RobotException {
|
||||
String ausgabe = "";
|
||||
for (int i = 0; i < zahlen.length; i++) {
|
||||
ausgabe = ausgabe + zahlen[i] +",";
|
||||
}
|
||||
return ausgabe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package Domäne;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import tpe.exceptions.roboter.Robot;
|
||||
import tpe.exceptions.roboter.RobotException;
|
||||
|
||||
|
@ -53,8 +55,18 @@ public abstract class Roboter implements Robot {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String speak(int[] zahlen) throws RobotException;
|
||||
public String speak(int[] zahlen, RobotType robotType) throws RobotException {
|
||||
if (robotType == RobotType.R2D2) {
|
||||
String ausgabe = "";
|
||||
Stream.of(zahlen).forEach(n -> ausgabe = ausgabe + n + ",");
|
||||
return ausgabe;
|
||||
}
|
||||
else if (robotType == RobotType.C3PO) {
|
||||
String ausgabe = "";
|
||||
Stream.of(zahlen).forEach(n -> ausgabe = ausgabe + n + ";");
|
||||
return ausgabe;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue