Erste Funktionalität bei R2D2

main
Lukas Berens 2022-12-28 12:22:05 +01:00
parent 2eabdd9375
commit 5679d63e71
1 changed files with 34 additions and 10 deletions

View File

@ -3,29 +3,39 @@ package tpe.exceptions.roboter;
import tpe.exceptions.roboter.exceptions.RobotException; import tpe.exceptions.roboter.exceptions.RobotException;
public class R2D2 implements RobotControl, RobotInstructions { public class R2D2 implements RobotControl, RobotInstructions {
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;
}
@Override @Override
public int getId() { public int getId() {
// TODO Auto-generated method stub return id;
return 0;
} }
@Override @Override
public String getName() { public String getName() {
// TODO Auto-generated method stub return name;
return null;
} }
@Override @Override
public void triggerPowerSwitch() { public void triggerPowerSwitch() {
// TODO Auto-generated method stub if(powerSwitch=false)
powerSwitch=true;
else
powerSwitch=false;
} }
@Override @Override
public boolean isPowerOn() { public boolean isPowerOn() {
// TODO Auto-generated method stub return powerSwitch;
return false;
} }
@Override @Override
@ -42,8 +52,22 @@ public class R2D2 implements RobotControl, RobotInstructions {
@Override @Override
public int[] think(int[] zahlen) { public int[] think(int[] zahlen) {
// TODO Auto-generated method stub // Iterate through zahlen from left to right
return null; 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;
} }
} }