diff --git a/bin/C3PO.class b/bin/C3PO.class index cfa7783..5180443 100644 Binary files a/bin/C3PO.class and b/bin/C3PO.class differ diff --git a/bin/Nexus6.class b/bin/Nexus6.class index d56ae45..82a30f8 100644 Binary files a/bin/Nexus6.class and b/bin/Nexus6.class differ diff --git a/bin/R2D2.class b/bin/R2D2.class index 99b8a32..c720f49 100644 Binary files a/bin/R2D2.class and b/bin/R2D2.class differ diff --git a/src/C3PO.java b/src/C3PO.java index fdc0ce8..9196d28 100644 --- a/src/C3PO.java +++ b/src/C3PO.java @@ -5,22 +5,23 @@ import java.util.Arrays; import java.util.stream.Collectors; public class C3PO implements Robot { + //declaring private int id; private String name; private boolean isPowerOn; - + //returns id @Override public int getId() { return id; } - + //returns name @Override public String getName() { return name; } - + //returns isPorwerOn true if it's false @Override public void triggerPowerSwitch() { if(isPowerOn==false){ @@ -30,17 +31,19 @@ public class C3PO implements Robot { } } //tes test - + + //returns isPowerOn @Override public boolean isPowerOn() { return isPowerOn; } - + //creating a RobotException @Override public RobotException getLastException() { return null; } - + + //speak method that returns the sorted and formated numbers from the array zahlen @Override public String speak(int[] zahlen) throws RobotException { @@ -48,7 +51,10 @@ public class C3PO implements Robot { return arrayFormatieren(sortiert); } - + + //method to format the result + //Returns a Stream consisting of the elements of this stream,each boxed to an Integer and maps it into a String + //each element of the Stream is separated by ; private String arrayFormatieren(int[] zahlen){ var ergebnis = Arrays.stream(zahlen) .boxed() @@ -56,6 +62,8 @@ public class C3PO implements Robot { .collect(Collectors.joining(";")); return ergebnis; } + + //method that sorts the array zahlen with the Selectionsort-Algorithmin in descending order @Override public int[] think(int[] zahlen) throws RobotException { int n = zahlen.length; diff --git a/src/Nexus6.java b/src/Nexus6.java index 1338ab1..3a4f8bc 100644 --- a/src/Nexus6.java +++ b/src/Nexus6.java @@ -6,55 +6,55 @@ import java.util.Arrays; import java.util.stream.Collectors; public class Nexus6 implements Robot { - + //declaring and initializing private int id = 19281982; private String name = "pris"; private boolean isPowerOn = false; - + //creating an instance of Nexus private static Nexus6 instance = new Nexus6(); - + //constructor of Nexus private Nexus6() { } - + //instance of Nexus is null public static Nexus6 getInstance() { if (instance == null) instance = new Nexus6(); return instance; } - + //returns id @Override public int getId() { return id; } - + //returns name @Override public String getName() { return name; } - + //isPowerOn must be false @Override public void triggerPowerSwitch() { if(isPowerOn==false){ - isPowerOn=true; + isPowerOn=false; }else{ isPowerOn=false; } } - + //retruns isPowerOn @Override public boolean isPowerOn() { return isPowerOn; } - + //creating a RobotException @Override public RobotException getLastException() { return null; } - + @Override public String speak(int[] zahlen) /*throws RobotIllegalStateException */{ @@ -62,7 +62,7 @@ public class Nexus6 implements Robot { return arrayFormatieren(sortiert); } - + private String arrayFormatieren(int[] zahlen){ var ergebnis = Arrays.stream(zahlen) .boxed() diff --git a/src/R2D2.java b/src/R2D2.java index 502f6fa..12597aa 100644 --- a/src/R2D2.java +++ b/src/R2D2.java @@ -5,22 +5,23 @@ import java.util.Arrays; import java.util.stream.Collectors; public class R2D2 implements Robot { - private int id; + //declaring + private int id; private String name; private boolean isPowerOn; - + //returns id @Override public int getId() { return id; } - + //returns name @Override public String getName() { return name; } - + //returns isPorwerOn true if it's false @Override public void triggerPowerSwitch() { if(isPowerOn==false){ @@ -29,17 +30,17 @@ public class R2D2 implements Robot { isPowerOn=false; } } - + //returns isPowerOn @Override public boolean isPowerOn() { return isPowerOn; } - + //creating a RobotException @Override public RobotException getLastException() { return null; } - + //speak method that returns the sorted and formated numbers from the array zahlen @Override public String speak(int[] zahlen) throws RobotException { @@ -47,7 +48,9 @@ public class R2D2 implements Robot { return arrayFormatieren(sortiert); } - + //method to format the result + //Returns a Stream consisting of the elements of this stream,each boxed to an Integer and maps it into a String + //each element of the Stream is separated by , private String arrayFormatieren(int[] zahlen){ var ergebnis = Arrays.stream(zahlen) .boxed() @@ -55,6 +58,7 @@ public class R2D2 implements Robot { .collect(Collectors.joining(",")); return ergebnis; } + //method that sorts the array zahlen with the Selectionsort-Algorithmin in ascending order @Override public int[] think(int[] zahlen) throws RobotException { int n = zahlen.length;