generated from hummel/Bank-System
implements zu Robot geändert nach Anforderungen
parent
6807b436c5
commit
dbb7419f1e
|
@ -2,7 +2,7 @@ package tpe.exceptions.roboter;
|
|||
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
|
||||
public class C3PO implements RobotControl, RobotInstructions{
|
||||
public class C3PO implements Robot{
|
||||
|
||||
@Override
|
||||
public String speak(int[] zahlen) {
|
||||
|
|
|
@ -2,13 +2,12 @@ package tpe.exceptions.roboter;
|
|||
|
||||
import java.util.*;
|
||||
import tpe.exceptions.roboter.exceptions.RobotException;
|
||||
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
||||
|
||||
public class R2D2 implements RobotControl, RobotInstructions {
|
||||
public class R2D2 implements Robot {
|
||||
RobotException robotexception;
|
||||
private String name;
|
||||
private boolean powerSwitch;
|
||||
private int id;
|
||||
private RobotMagicValueException robotMagicValueException;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
public R2D2(String name, boolean powerSwitch) {
|
||||
|
@ -52,10 +51,8 @@ public class R2D2 implements RobotControl, RobotInstructions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String speak(int[] zahlen) {
|
||||
if(robotMagicValueException.invalidNumber(zahlen)==true)
|
||||
return "42 ist keine gültige Eingabe";
|
||||
else {
|
||||
public String speak(int[] zahlen) throws RobotException {
|
||||
|
||||
for (int i = 0; i < zahlen.length; i++) {
|
||||
sb.append(zahlen[i]);
|
||||
if (i < zahlen.length - 1) {
|
||||
|
@ -65,11 +62,14 @@ public class R2D2 implements RobotControl, RobotInstructions {
|
|||
|
||||
String output = sb.toString();
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public int[] think(int[] zahlen) {
|
||||
public int[] think(int[] zahlen) throws RobotException {
|
||||
for(int i = 0; i < zahlen.length; i++) {
|
||||
if(zahlen[i]==42)
|
||||
throw new RobotException.MagicValueException();
|
||||
}
|
||||
// Iterate through zahlen from left to right
|
||||
for (int i = 0; i < zahlen.length - 1; i++) {
|
||||
// Set the index of the current smallest element to i
|
||||
|
@ -86,6 +86,7 @@ public class R2D2 implements RobotControl, RobotInstructions {
|
|||
zahlen[minIndex] = temp;
|
||||
}
|
||||
return zahlen;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue