From 16947dde83fcb13e5d99d458637c76d1e0e08e4b Mon Sep 17 00:00:00 2001 From: Eline Date: Fri, 6 Jan 2023 17:10:53 +0100 Subject: [PATCH] comments --- bin/C3PO.class | Bin 2683 -> 2683 bytes bin/Nexus6.class | Bin 2862 -> 2862 bytes bin/R2D2.class | Bin 2683 -> 2683 bytes src/C3PO.java | 22 +++++++++++++++------- src/Nexus6.java | 24 ++++++++++++------------ src/R2D2.java | 20 ++++++++++++-------- 6 files changed, 39 insertions(+), 27 deletions(-) diff --git a/bin/C3PO.class b/bin/C3PO.class index cfa7783ee8cb82853b1301c4206a1c4030b11449..5180443046a0f2ca7aeffe224979ae092c32b228 100644 GIT binary patch delta 143 zcmW;CISRr+7(n4SxXc6;iDqovqKG0kA}PeUff(0dZRHKTgOvyP3$LLU@)UMy40a#9 zmw1WyT5ILXU0b>6zN)4=xivI(3N$Fu#KV`5j#Te|O-)w~~ n!GbO!Jt7Ic=VV2WHHHmkw$zDn?C{ys&m3?h%6d#9U+?h)vacAb diff --git a/bin/Nexus6.class b/bin/Nexus6.class index d56ae451292eb691212be87f54e78315ea9e24e5..82a30f89f12d0f260b4a791298e8fcca058371d8 100644 GIT binary patch delta 14 VcmZ1{woYtA1qUPZ=1PvOOaLY#1gHQ2 delta 14 VcmZ1{woYtA1qUO`=1PvOOaLY*1gQW3 diff --git a/bin/R2D2.class b/bin/R2D2.class index 99b8a3294c8944ca0b1d5819ad1952bc9bc3b1eb..c720f49386e6737891735e2d066f0c20e12c2c8b 100644 GIT binary patch delta 143 zcmW;DOAf(M7(n53<8f~jBBj^FtE7o^ghWzm(khJz3ox<+doZ$qe_$JI$STY_(U^UM za|*BUUYS;|+_ja9o~mxCliNenr@??0Lp*%>=v)Q=DmH-%YsMo?$|T6vLJ#8Etl0_Ke7xl%8`azm$Zde4WP+zseZ% delta 143 zcmW;CISRr+7(n4SxXc6;x0%L;xPjV8il{+c;zBAtfR#7!4ptuEFT93c$Wz#*G1z_Z zUTRbOI%rjuyLNKXBjqxkYE3jPO0=oa!Q#tDCu;D&mS(8Nay93|lp=w=&CP}6nc*>~ n!GbO!Jt7Ic=VV2WHHHmkw$zDn?C{ys&m3?h%6d#9U+?h)vacAb 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;