2022-12-27 11:09:41 +01:00
|
|
|
package tpe.exceptions.roboter;
|
|
|
|
|
|
|
|
import tpe.exceptions.roboter.exceptions.RobotException;
|
|
|
|
|
|
|
|
public class R2D2 implements RobotControl, RobotInstructions {
|
2022-12-28 12:22:05 +01:00
|
|
|
private static int counter = 0;
|
|
|
|
private String name;
|
|
|
|
private boolean powerSwitch;
|
|
|
|
private int id;
|
|
|
|
|
|
|
|
public R2D2(String name, boolean powerSwitch) {
|
|
|
|
super();
|
|
|
|
id = 0+counter;
|
|
|
|
this.name = name;
|
|
|
|
this.powerSwitch = powerSwitch;
|
|
|
|
}
|
2022-12-27 11:09:41 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getId() {
|
2022-12-28 12:22:05 +01:00
|
|
|
return id;
|
2022-12-27 11:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2022-12-28 12:22:05 +01:00
|
|
|
return name;
|
2022-12-27 11:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void triggerPowerSwitch() {
|
2022-12-28 12:22:05 +01:00
|
|
|
if(powerSwitch=false)
|
|
|
|
powerSwitch=true;
|
|
|
|
else
|
|
|
|
powerSwitch=false;
|
2022-12-27 11:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPowerOn() {
|
2022-12-28 12:22:05 +01:00
|
|
|
return powerSwitch;
|
2022-12-27 11:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RobotException getLastException() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String speak(int[] zahlen) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] think(int[] zahlen) {
|
2022-12-28 12:22:05 +01:00
|
|
|
// 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
|
|
|
|
int minIndex = i;
|
|
|
|
// Search the smallest element in zahlen
|
|
|
|
for (int j = i + 1; j < zahlen.length; j++) {
|
|
|
|
if (zahlen[j] < zahlen[minIndex]) {
|
|
|
|
minIndex = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Switch the smallest with the current element
|
|
|
|
int temp = zahlen[i];
|
|
|
|
zahlen[i] = zahlen[minIndex];
|
|
|
|
zahlen[minIndex] = temp;
|
|
|
|
}
|
|
|
|
return zahlen;
|
2022-12-27 11:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|