RoboterFabrik/Roboter/tpe/exceptions/roboter/R2D2.java

61 lines
1.3 KiB
Java

package tpe.exceptions.roboter;
import java.util.*;
import tpe.exceptions.RobotException;
import tpe.exceptions.RobotIllegalStateException;
import tpe.exceptions.RobotMagicValueException;
public class R2D2 extends Robots {
RobotType robotType;
private int id;
StringBuilder sb = new StringBuilder();
/**
* Inititalisert R2D2 und weist {@link RobotType} zu
* @param name
* @param id
*/
public R2D2(String name,int id) {
super(name);
this.id=id;
this.name = name;
robotType= RobotType.R2D2;
}
@Override
public int getId() {
return id;
}
@Override
public int[] think(int[] zahlen) throws RobotException {
// 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;
}
/**
*
* @return Gibt {@link RobotType} zurück
*/
public RobotType getRobotType () {
return this.robotType;
}
}