master
Eline 2022-12-29 11:30:12 +01:00
parent 55264c293e
commit efd9dba445
4 changed files with 96 additions and 0 deletions

6
.classpath 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
/bin/

17
.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Robot</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

72
src/R2D2.java 100644
View File

@ -0,0 +1,72 @@
import tpe.exceptions.roboter.Robot;
import tpe.exceptions.roboter.exceptions.RobotException;
import java.util.Arrays;
import java.util.stream.Collectors;
public class R2D2 implements Robot {
private int id;
private String name;
private boolean isPowerOn;
@Override
public int getId() {
return id;
}
@Override
public String getName() {
return name;
}
@Override
public void triggerPowerSwitch() {
if(isPowerOn==false){
isPowerOn=true;
}else{
isPowerOn=false;
}
}
@Override
public boolean isPowerOn() {
return isPowerOn;
}
@Override
public RobotException getLastException() {
return null;
}
@Override
public String speak(int[] zahlen) throws RobotException {
var sortiert = think(zahlen);
return arrayFormatieren(sortiert);
}
private String arrayFormatieren(int[] zahlen){
var ergebnis = Arrays.stream(zahlen)
.boxed()
.map(String::valueOf)
.collect(Collectors.joining(","));
return ergebnis;
}
@Override
public int[] think(int[] zahlen) throws RobotException {
int n = zahlen.length;
for (int i = 1; i < n; ++i) {
int key = zahlen[i];
int j = i - 1;
while (j >= 0 && zahlen[j] < key) {
zahlen[j + 1] = zahlen[j];
j = j - 1;
}
zahlen[j + 1] = key;
}
return zahlen;
}
}