Singleton

master
Eline 2022-12-30 03:08:38 +01:00
parent 27519b8f79
commit fc67d7b309
3 changed files with 18 additions and 12 deletions

View File

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

View File

@ -1,21 +1,23 @@
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 int id;
private String name;
private boolean isPowerOn;
private Nexus6() {
}
public static Nexus6 getInstance() {
if (instance == null)
instance = new Nexus6();
@ -25,12 +27,12 @@ public class Nexus6 implements Robot {
@Override
public int getId() {
return 19281982;
return id;
}
@Override
public String getName() {
return "pris";
return name;
}
@Override
@ -41,6 +43,7 @@ public class Nexus6 implements Robot {
isPowerOn=false;
}
}
@Override
public boolean isPowerOn() {
@ -53,7 +56,7 @@ public class Nexus6 implements Robot {
}
@Override
public String speak(int[] zahlen) throws RobotException {
public String speak(int[] zahlen) /*throws RobotIllegalStateException */{
var sortiert = think(zahlen);
@ -68,7 +71,7 @@ public class Nexus6 implements Robot {
return ergebnis;
}
@Override
public int[] think(int[] zahlen) throws RobotException {
public int[] think(int[] zahlen) /*throws RobotIllegalStateException*/ {
int n = zahlen.length;
for (int i = 1; i < n; ++i) {
int key = zahlen[i];
@ -81,4 +84,7 @@ public class Nexus6 implements Robot {
}
return zahlen;
}
}

View File

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