Merge remote-tracking branch 'origin/Eline'

master
azadehobenland 2023-01-05 18:07:10 +01:00
commit dabe1dda0f
6 changed files with 187 additions and 1 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>

View File

@ -62,7 +62,7 @@ public class C3PO implements Robot {
for (int i = 1; i < n; ++i) { for (int i = 1; i < n; ++i) {
int key = zahlen[i]; int key = zahlen[i];
int j = i - 1; int j = i - 1;
while (j >= 0 && zahlen[j] > key) { while (j >= 0 && zahlen[j] < key) {
zahlen[j + 1] = zahlen[j]; zahlen[j + 1] = zahlen[j];
j = j - 1; j = j - 1;
} }

90
src/Nexus6.java 100644
View File

@ -0,0 +1,90 @@
import tpe.exceptions.roboter.Robot;
import tpe.exceptions.roboter.exceptions.RobotException;
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
import java.util.Arrays;
import java.util.stream.Collectors;
public class Nexus6 implements Robot {
private int id = 19281982;
private String name = "pris";
private boolean isPowerOn = false;
private static Nexus6 instance = new Nexus6();
private Nexus6() {
}
public static Nexus6 getInstance() {
if (instance == null)
instance = new Nexus6();
return instance;
}
@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 RobotIllegalStateException */{
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 RobotIllegalStateException*/ {
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;
}
}

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;
}
}