diff --git a/RobotAbgabe.iml b/RobotAbgabe.iml
index c90834f..901477e 100644
--- a/RobotAbgabe.iml
+++ b/RobotAbgabe.iml
@@ -3,9 +3,36 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bin/C3PO.class b/bin/C3PO.class
deleted file mode 100644
index 174c0db..0000000
Binary files a/bin/C3PO.class and /dev/null differ
diff --git a/bin/Nexus6.class b/bin/Nexus6.class
deleted file mode 100644
index 82a30f8..0000000
Binary files a/bin/Nexus6.class and /dev/null differ
diff --git a/bin/R2D2.class b/bin/R2D2.class
deleted file mode 100644
index f50ae3f..0000000
Binary files a/bin/R2D2.class and /dev/null differ
diff --git a/bin/tpe/exceptions/roboter/Robot.class b/bin/tpe/exceptions/roboter/Robot.class
deleted file mode 100644
index a728b70..0000000
Binary files a/bin/tpe/exceptions/roboter/Robot.class and /dev/null differ
diff --git a/bin/tpe/exceptions/roboter/RobotControl.class b/bin/tpe/exceptions/roboter/RobotControl.class
deleted file mode 100644
index 270ad94..0000000
Binary files a/bin/tpe/exceptions/roboter/RobotControl.class and /dev/null differ
diff --git a/bin/tpe/exceptions/roboter/RobotInstructions.class b/bin/tpe/exceptions/roboter/RobotInstructions.class
deleted file mode 100644
index 17111db..0000000
Binary files a/bin/tpe/exceptions/roboter/RobotInstructions.class and /dev/null differ
diff --git a/bin/tpe/exceptions/roboter/exceptions/RobotException.class b/bin/tpe/exceptions/roboter/exceptions/RobotException.class
deleted file mode 100644
index c885bb9..0000000
Binary files a/bin/tpe/exceptions/roboter/exceptions/RobotException.class and /dev/null differ
diff --git a/bin/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.class b/bin/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.class
deleted file mode 100644
index b9a61a1..0000000
Binary files a/bin/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.class and /dev/null differ
diff --git a/bin/tpe/exceptions/roboter/exceptions/RobotMagicValueException.class b/bin/tpe/exceptions/roboter/exceptions/RobotMagicValueException.class
deleted file mode 100644
index 36198c6..0000000
Binary files a/bin/tpe/exceptions/roboter/exceptions/RobotMagicValueException.class and /dev/null differ
diff --git a/out/production/RobotAbgabe/roboter/C3PO.class b/out/production/RobotAbgabe/roboter/C3PO.class
new file mode 100644
index 0000000..d18e1a7
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/C3PO.class differ
diff --git a/out/production/RobotAbgabe/roboter/Nexus6.class b/out/production/RobotAbgabe/roboter/Nexus6.class
new file mode 100644
index 0000000..ed8d714
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/Nexus6.class differ
diff --git a/out/production/RobotAbgabe/roboter/R2D2.class b/out/production/RobotAbgabe/roboter/R2D2.class
new file mode 100644
index 0000000..51f6cae
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/R2D2.class differ
diff --git a/out/production/RobotAbgabe/roboter/Robot.class b/out/production/RobotAbgabe/roboter/Robot.class
new file mode 100644
index 0000000..721818b
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/Robot.class differ
diff --git a/out/production/RobotAbgabe/roboter/RobotControl.class b/out/production/RobotAbgabe/roboter/RobotControl.class
new file mode 100644
index 0000000..8578f06
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/RobotControl.class differ
diff --git a/out/production/RobotAbgabe/roboter/RobotFactory$1.class b/out/production/RobotAbgabe/roboter/RobotFactory$1.class
new file mode 100644
index 0000000..56b2d85
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/RobotFactory$1.class differ
diff --git a/out/production/RobotAbgabe/roboter/RobotFactory.class b/out/production/RobotAbgabe/roboter/RobotFactory.class
new file mode 100644
index 0000000..f685e35
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/RobotFactory.class differ
diff --git a/out/production/RobotAbgabe/roboter/RobotInstructions.class b/out/production/RobotAbgabe/roboter/RobotInstructions.class
new file mode 100644
index 0000000..59837e5
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/RobotInstructions.class differ
diff --git a/out/production/RobotAbgabe/roboter/Typ.class b/out/production/RobotAbgabe/roboter/Typ.class
new file mode 100644
index 0000000..e183cc0
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/Typ.class differ
diff --git a/out/production/RobotAbgabe/roboter/exceptions/RobotException.class b/out/production/RobotAbgabe/roboter/exceptions/RobotException.class
new file mode 100644
index 0000000..bd6093a
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/exceptions/RobotException.class differ
diff --git a/out/production/RobotAbgabe/roboter/exceptions/RobotIllegalStateException.class b/out/production/RobotAbgabe/roboter/exceptions/RobotIllegalStateException.class
new file mode 100644
index 0000000..347a57f
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/exceptions/RobotIllegalStateException.class differ
diff --git a/out/production/RobotAbgabe/roboter/exceptions/RobotMagicValueException.class b/out/production/RobotAbgabe/roboter/exceptions/RobotMagicValueException.class
new file mode 100644
index 0000000..22b789f
Binary files /dev/null and b/out/production/RobotAbgabe/roboter/exceptions/RobotMagicValueException.class differ
diff --git a/out/test/RobotAbgabe/roboter/C3PoSortierungTest.class b/out/test/RobotAbgabe/roboter/C3PoSortierungTest.class
new file mode 100644
index 0000000..a0eb51e
Binary files /dev/null and b/out/test/RobotAbgabe/roboter/C3PoSortierungTest.class differ
diff --git a/out/test/RobotAbgabe/roboter/ExceptionTest.class b/out/test/RobotAbgabe/roboter/ExceptionTest.class
new file mode 100644
index 0000000..8051207
Binary files /dev/null and b/out/test/RobotAbgabe/roboter/ExceptionTest.class differ
diff --git a/out/test/RobotAbgabe/roboter/FactoryTest.class b/out/test/RobotAbgabe/roboter/FactoryTest.class
new file mode 100644
index 0000000..0278463
Binary files /dev/null and b/out/test/RobotAbgabe/roboter/FactoryTest.class differ
diff --git a/out/test/RobotAbgabe/roboter/GetLastExceptionTest.class b/out/test/RobotAbgabe/roboter/GetLastExceptionTest.class
new file mode 100644
index 0000000..2fe3bd4
Binary files /dev/null and b/out/test/RobotAbgabe/roboter/GetLastExceptionTest.class differ
diff --git a/out/test/RobotAbgabe/roboter/R2D2Test.class b/out/test/RobotAbgabe/roboter/R2D2Test.class
new file mode 100644
index 0000000..3a51ee9
Binary files /dev/null and b/out/test/RobotAbgabe/roboter/R2D2Test.class differ
diff --git a/src/C3PO.java b/src/C3PO.java
deleted file mode 100644
index e915b08..0000000
--- a/src/C3PO.java
+++ /dev/null
@@ -1,107 +0,0 @@
-import tpe.exceptions.roboter.Robot;
-import tpe.exceptions.roboter.exceptions.RobotException;
-
-import java.util.Arrays;
-import java.util.stream.Collectors;
-
-public class C3PO implements Robot {
-
- private int id;
- private String name;
- private boolean isPowerOn;
-
-
- /**
- * @return id of the robot
- */
- @Override
- public int getId() {
- return id;
- }
-
- /**
- * @return name of the robot
- */
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * @return isPorwerOn true if it's false
- */
- @Override
- public void triggerPowerSwitch() {
- if(isPowerOn==false){
- isPowerOn=true;
- }else{
- isPowerOn=false;
- }
- }
- //tes test
-
- /**
- * @return isPowerOn
- */
- @Override
- public boolean isPowerOn() {
- return isPowerOn;
- }
-
- /**
- * creating a RobotException getLastException
- */
- @Override
- public RobotException getLastException() {
- return null;
- }
-
- /**
- * speak method that returns the sorted and formated numbers from the array zahlen
- * @param int[] zahlen Array of numbers for sorting
- * @return sorted and formated numbers
- */
- @Override
- public String speak(int[] zahlen) throws RobotException {
-
- var sortiert = think(zahlen);
-
- return arrayFormatieren(sortiert);
- }
-
- /**
- * method to format the outcome
- * 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 ","
- * @param int[] zahlen Array of numbers to sort
- * @return formated outcome
- */
- private String arrayFormatieren(int[] zahlen){
- var ergebnis = Arrays.stream(zahlen)
- .boxed()
- .map(String::valueOf)
- .collect(Collectors.joining(";"));
- return ergebnis;
- }
-
- /**
- * method that sorts the array zahlen with the Selectionsort-Algorithmin in descending order
- * @param int[] zahlen Array of numbers for sorting
- * @return array of numbers in descending order
- */
- @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;
- }
-}
diff --git a/src/Nexus6.java b/src/Nexus6.java
deleted file mode 100644
index 5906c64..0000000
--- a/src/Nexus6.java
+++ /dev/null
@@ -1,90 +0,0 @@
-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;
-
- //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=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 */{
-
- 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;
- }
-
-
-
-}
diff --git a/src/R2D2.java b/src/R2D2.java
deleted file mode 100644
index 62e644b..0000000
--- a/src/R2D2.java
+++ /dev/null
@@ -1,105 +0,0 @@
-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;
-
-
- /**
- * @return id of the robot
- */
- @Override
- public int getId() {
- return id;
- }
-
- /**
- * @return name of the robot
- */
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * @return isPorwerOn true if it's false
- */
- @Override
- public void triggerPowerSwitch() {
- if(isPowerOn==false){
- isPowerOn=true;
- }else{
- isPowerOn=false;
- }
- }
-
- /**
- * @return isPowerOn
- */
- @Override
- public boolean isPowerOn() {
- return isPowerOn;
- }
-
- /**
- * creating a RobotException getLastException
- */
- @Override
- public RobotException getLastException() {
- return null;
- }
-
- /**
- * speak method that returns the sorted and formated numbers from the array zahlen
- * @param int[] zahlen Array of numbers for sorting
- * @return sorted and formated numbers
- */
- @Override
- public String speak(int[] zahlen) throws RobotException {
-
- var sortiert = think(zahlen);
-
- return arrayFormatieren(sortiert);
- }
-
- /**
- * method to format the outcome
- * 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 ","
- * @param int[] zahlen Array of numbers to sort
- * @return formated outcome
- */
- private String arrayFormatieren(int[] zahlen){
- var ergebnis = Arrays.stream(zahlen)
- .boxed()
- .map(String::valueOf)
- .collect(Collectors.joining(","));
- return ergebnis;
- }
- /**
- * method that sorts the array zahlen with the Selectionsort-Algorithmin in ascending order
- * @param int[] zahlen Array of numbers for sorting
- * @return array of numbers in ascending order
- */
- @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;
- }
-}
diff --git a/src/main/java/roboter/C3PO.java b/src/main/java/roboter/C3PO.java
new file mode 100644
index 0000000..a69f38e
--- /dev/null
+++ b/src/main/java/roboter/C3PO.java
@@ -0,0 +1,108 @@
+package roboter;
+
+import roboter.exceptions.RobotException;
+import roboter.exceptions.RobotIllegalStateException;
+import roboter.exceptions.RobotMagicValueException;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class C3PO implements Robot {
+ private int id;
+ private String name;
+ private boolean isPowerOn = true;
+ ArrayList exceptionList=new ArrayList<>();
+
+ public C3PO(int id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ @Override
+ public int getId() {
+ return id;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void triggerPowerSwitch() {
+ if (isPowerOn == false) {
+ isPowerOn = true;
+ } else {
+ isPowerOn = false;
+ }
+ }
+ //tes test
+
+ @Override
+ public boolean isPowerOn() {
+ return isPowerOn;
+ }
+
+ @Override
+ public RobotException getLastException() {
+ if (!exceptionList.isEmpty()){
+ return exceptionList.get(exceptionList.size() - 1);
+
+ }
+ return null;
+ }
+
+ @Override
+ public String speak(int[] zahlen) throws RobotException, RobotMagicValueException {
+ if(!isPowerOn){
+ var ex=new RobotIllegalStateException(this);
+ exceptionList.add(ex);
+ throw ex;
+ }
+ if (Arrays.stream(zahlen).anyMatch(value -> value ==42)){
+ var exc= new RobotMagicValueException(this);
+ exceptionList.add(exc);
+ throw exc;
+ }
+ var sortiert = think(zahlen);
+
+ return arrayFormatieren(sortiert);
+ }
+
+ private String arrayFormatieren(int[] zahlen) throws RobotMagicValueException {
+
+ var ergebnis = Arrays.stream(zahlen)
+ .boxed()
+ .map(String::valueOf)
+ .collect(Collectors.joining(";"));
+ return ergebnis;
+ }
+
+ @Override
+ public int[] think(int[] zahlen) throws RobotException {
+ if(!isPowerOn){
+ var ex=new RobotIllegalStateException(this);
+ exceptionList.add(ex);
+ throw ex;
+ }
+ if (Arrays.stream(zahlen).anyMatch(value -> value ==42)){
+ var exc= new RobotMagicValueException(this);
+ exceptionList.add(exc);
+ throw exc;
+ }
+ 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;
+ }
+}
diff --git a/src/main/java/roboter/Nexus6.java b/src/main/java/roboter/Nexus6.java
new file mode 100644
index 0000000..516f6f6
--- /dev/null
+++ b/src/main/java/roboter/Nexus6.java
@@ -0,0 +1,79 @@
+package roboter;
+
+import roboter.exceptions.RobotException;
+import roboter.exceptions.RobotIllegalStateException;
+import roboter.exceptions.RobotException;
+
+import java.util.ArrayList;
+
+public class Nexus6 implements Robot {
+
+ private int id = 19281982;
+ private String name = "pris";
+ private boolean isPowerOn = false;
+ ArrayList exceptionList=new ArrayList<>();
+
+ 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() {
+
+ }
+
+
+ @Override
+ public boolean isPowerOn() {
+ return isPowerOn;
+ }
+
+ @Override
+ public RobotException getLastException() {
+ if (!exceptionList.isEmpty()){
+ return exceptionList.get(exceptionList.size() - 1);
+
+ }
+ return null;
+ }
+
+ @Override
+ public String speak(int[] zahlen) throws RobotIllegalStateException {
+ var newException = new RobotIllegalStateException(this);
+ exceptionList.add(newException);
+ throw newException;
+
+ }
+
+
+ @Override
+ public int[] think(int[] zahlen) throws RobotIllegalStateException {
+ var newException2=new RobotIllegalStateException(this);
+ exceptionList.add(newException2);
+ throw newException2;
+
+ }
+
+
+
+}
diff --git a/src/main/java/roboter/R2D2.java b/src/main/java/roboter/R2D2.java
new file mode 100644
index 0000000..75aba33
--- /dev/null
+++ b/src/main/java/roboter/R2D2.java
@@ -0,0 +1,105 @@
+package roboter;
+
+import roboter.exceptions.RobotException;
+import roboter.exceptions.RobotIllegalStateException;
+import roboter.exceptions.RobotMagicValueException;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+public class R2D2 implements Robot {
+ private int id;
+ private String name;
+ private boolean isPowerOn=true;
+ ArrayList exceptionList=new ArrayList<>();
+
+ public R2D2(int id, String name){
+ this.id=id;
+ this.name=name;
+ }
+
+
+
+ @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() {
+ if (!exceptionList.isEmpty()){
+ return exceptionList.get(exceptionList.size() - 1);
+
+ }
+ return null;
+ }
+
+ @Override
+ public String speak(int[] zahlen) throws RobotException, RobotMagicValueException {
+ if(!isPowerOn){
+ var ex=new RobotIllegalStateException(this);
+ exceptionList.add(ex);
+ throw ex;
+ }
+ if (Arrays.stream(zahlen).anyMatch(value -> value ==42)){
+ var exc= new RobotMagicValueException(this);
+ exceptionList.add(exc);
+ throw exc;
+ }
+ 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, RobotMagicValueException {
+ if(!isPowerOn){
+ var ex=new RobotIllegalStateException(this);
+ exceptionList.add(ex);
+ throw ex;
+ }
+ if (Arrays.stream(zahlen).anyMatch(value -> value ==42)){
+ var exc= new RobotMagicValueException(this);
+ exceptionList.add(exc);
+ throw exc;
+ }
+ for (int i = 0; i < zahlen.length - 1; i++) {
+ for (int j = i + 1; j < zahlen.length; j++) {
+ if (zahlen[i] > zahlen[j]) {
+ int temp = zahlen[i];
+ zahlen[i] = zahlen[j];
+ zahlen[j] = temp;
+ }
+ }
+ }
+
+ return zahlen;
+ }
+}
diff --git a/src/tpe/exceptions/roboter/Robot.java b/src/main/java/roboter/Robot.java
similarity index 87%
rename from src/tpe/exceptions/roboter/Robot.java
rename to src/main/java/roboter/Robot.java
index 61069b4..57f3f28 100644
--- a/src/tpe/exceptions/roboter/Robot.java
+++ b/src/main/java/roboter/Robot.java
@@ -1,6 +1,6 @@
/* (c) 2012 Thomas Smits */
-package tpe.exceptions.roboter;
+package roboter;
/**
* Interface für Roboter.
diff --git a/src/tpe/exceptions/roboter/RobotControl.java b/src/main/java/roboter/RobotControl.java
similarity index 96%
rename from src/tpe/exceptions/roboter/RobotControl.java
rename to src/main/java/roboter/RobotControl.java
index 5e9ab20..651882d 100644
--- a/src/tpe/exceptions/roboter/RobotControl.java
+++ b/src/main/java/roboter/RobotControl.java
@@ -1,7 +1,8 @@
-package tpe.exceptions.roboter;
+package roboter;
-import tpe.exceptions.roboter.exceptions.RobotException;
+import roboter.exceptions.RobotException;
+import roboter.exceptions.RobotException;
/**
* Das Interface repräsentiert einen einfachen Roboter mit seinen Funktionen.
diff --git a/src/main/java/roboter/RobotFactory.java b/src/main/java/roboter/RobotFactory.java
new file mode 100644
index 0000000..af67b8a
--- /dev/null
+++ b/src/main/java/roboter/RobotFactory.java
@@ -0,0 +1,29 @@
+package roboter;
+
+public class RobotFactory {
+ private static int R2D2Id=0;
+ private static int C2POId=10000;
+
+ /**
+ * Dies ist eine Factory methode, mit der man einen Roboter
+ * mit einem bestimmten typ und namen generieren lassen kann
+ * @param typ Typ vom Roboter
+ * @param name Name vom Roboter
+ * @return ein Roboter Objekt
+ */
+ public static Robot getRobot(Typ typ,String name){
+ switch (typ){
+ case R2D2:
+ return new R2D2(R2D2Id++,name);
+
+ case C3PO:
+ return new C3PO(C2POId++,name);
+
+ case Nexus6:
+ return Nexus6.getInstance();
+
+ }
+ return null;
+ }
+
+}
diff --git a/src/tpe/exceptions/roboter/RobotInstructions.java b/src/main/java/roboter/RobotInstructions.java
similarity index 84%
rename from src/tpe/exceptions/roboter/RobotInstructions.java
rename to src/main/java/roboter/RobotInstructions.java
index 4085249..c88e436 100644
--- a/src/tpe/exceptions/roboter/RobotInstructions.java
+++ b/src/main/java/roboter/RobotInstructions.java
@@ -1,9 +1,9 @@
-package tpe.exceptions.roboter;
+package roboter;
-import tpe.exceptions.roboter.exceptions.RobotException;
-import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
-import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
+import roboter.exceptions.RobotException;
+import roboter.exceptions.RobotIllegalStateException;
+import roboter.exceptions.RobotMagicValueException;
/**
* Das Interface repräsentiert den Befehlssatz eines einfachen Roboters.
@@ -35,7 +35,7 @@ public interface RobotInstructions {
* @throws RobotException wenn der Roboter in einem ungültigen Zustand ist,
* oder das Array nicht seinen Vorstellungen entspricht.
*/
- public String speak(int[] zahlen) throws RobotException;
+ public String speak(int[] zahlen) throws RobotException, RobotMagicValueException;
/**
* Sortiert ein Array von Zahlen. Die Reihenfolge hängt von dem Typ des
@@ -46,5 +46,5 @@ public interface RobotInstructions {
* @throws RobotException wenn der Roboter in einem ungültigen Zustand ist,
* oder das Array nicht seinen Vorstellungen entspricht.
*/
- public int[] think(int[] zahlen) throws RobotException;
+ public int[] think(int[] zahlen) throws RobotException, RobotMagicValueException;
}
\ No newline at end of file
diff --git a/src/main/java/roboter/Typ.java b/src/main/java/roboter/Typ.java
new file mode 100644
index 0000000..22df119
--- /dev/null
+++ b/src/main/java/roboter/Typ.java
@@ -0,0 +1,5 @@
+package roboter;
+
+public enum Typ {
+ R2D2,C3PO,Nexus6
+}
diff --git a/src/main/java/roboter/exceptions/RobotException.java b/src/main/java/roboter/exceptions/RobotException.java
new file mode 100644
index 0000000..190cb72
--- /dev/null
+++ b/src/main/java/roboter/exceptions/RobotException.java
@@ -0,0 +1,7 @@
+package roboter.exceptions;
+
+public class RobotException extends Exception{
+ public RobotException(String errormessage) {
+ super(errormessage);
+ }
+}
diff --git a/src/main/java/roboter/exceptions/RobotIllegalStateException.java b/src/main/java/roboter/exceptions/RobotIllegalStateException.java
new file mode 100644
index 0000000..9ab52ae
--- /dev/null
+++ b/src/main/java/roboter/exceptions/RobotIllegalStateException.java
@@ -0,0 +1,11 @@
+package roboter.exceptions;
+
+import roboter.Robot;
+import roboter.exceptions.*;
+public class RobotIllegalStateException extends RobotException {
+
+ public RobotIllegalStateException(Robot roboter) {
+
+ super("Fehler von : " + roboter.getName());
+ }
+}
diff --git a/src/main/java/roboter/exceptions/RobotMagicValueException.java b/src/main/java/roboter/exceptions/RobotMagicValueException.java
new file mode 100644
index 0000000..d7e1a83
--- /dev/null
+++ b/src/main/java/roboter/exceptions/RobotMagicValueException.java
@@ -0,0 +1,9 @@
+package roboter.exceptions;
+
+import roboter.Robot;
+
+public class RobotMagicValueException extends RobotException {
+ public RobotMagicValueException(Robot robot) {
+ super(robot.getName());
+ }
+}
diff --git a/src/test/java/roboter/C3POTest.java b/src/test/java/roboter/C3POTest.java
new file mode 100644
index 0000000..67e6a6d
--- /dev/null
+++ b/src/test/java/roboter/C3POTest.java
@@ -0,0 +1,68 @@
+package test.java.roboter;
+
+import org.junit.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DynamicNode;
+import roboter.exceptions.RobotException;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Properties;
+
+public class C3POTest {
+
+ private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ private final ByteArrayOutputStream err = new ByteArrayOutputStream();
+ private final PrintStream originalOut = System.out;
+ private final PrintStream originalErr = System.err;
+
+ @Before
+ public void setStreams() {
+ System.setOut(new PrintStream(out));
+ System.setErr(new PrintStream(err));
+ }
+
+ @After
+ public void restoreInitialStreams() {
+ System.setOut(originalOut);
+ System.setErr(originalErr);
+ }
+ @Test
+ public void sortieren() throws RobotException {
+ var list = new int[]{12,6,7,10,18,2};
+ Robot robot= RobotFactory.getRobot(Typ.C3PO,"roboter2");
+
+ Assert.assertEquals("18,12,10,7,6,2",robot.speak(list));
+
+ var list1 = new int[] {17,10,19,1,4,2,7};
+ Assert.assertEquals("19,17,10,7,4,2,1", robot.speak(list));
+
+ var list2 = new int[] {3,17,7,20,5,15,8};
+ Assert.assertEquals("20,17,15,8,7,5,3", robot.speak(list));
+
+ var list3 = new int[] {13,8,5,12,1,9,7};
+ Assert.assertEquals("13,12,9,8,7,5,1", robot.speak(list));
+
+ var list4 = new int[] {18,4,21,7,3,2,9};
+ Assert.assertEquals("21,18,9,7,4,3,2", robot.speak(list));
+
+ var list5 = new int[] {13,23,8,4,22,6};
+ Assert.assertEquals("23,22,13,8,6,4", robot.speak(list));
+
+ var list6 = new int[] {10,9,8,7,6,5};
+ Assert.assertEquals("10,9,8,7,6,5", robot.speak(list));
+
+ var list7 = new int[] {1,2,3,5,4,6};
+ Assert.assertEquals("6,5,4,3,2,1", robot.speak(list));
+
+ var list8 = new int[] {20,19,18,17,16,15};
+ Assert.assertEquals("20,19,18,17,16,15", robot.speak(list));
+
+ var list9 = new int[] {15,1,13,10,7,4};
+ Assert.assertEquals("15,13,10,7,4,1", robot.speak(list));
+
+ var list10 = new int[] {10,15,11,8,5,6,};
+ Assert.assertEquals("15,11,10,8,6,5", robot.speak(list));
+ }
+}
diff --git a/src/test/java/roboter/C3PoSortierungTest.java b/src/test/java/roboter/C3PoSortierungTest.java
new file mode 100644
index 0000000..2f70dc1
--- /dev/null
+++ b/src/test/java/roboter/C3PoSortierungTest.java
@@ -0,0 +1,20 @@
+package roboter;
+
+import org.junit.Assert;
+import org.junit.Test;
+import roboter.exceptions.RobotException;
+
+public class C3PoSortierungTest {
+
+ @Test
+ public void sortieren() throws RobotException {
+ var list = new int[]{12,6,7,10,18,2};
+ Robot robot= RobotFactory.getRobot(Typ.C3PO,"roboter2");
+
+
+ assert robot != null;
+ Assert.assertEquals("2;6;7;10;12;18",robot.speak(list));
+ }
+
+
+}
diff --git a/src/test/java/roboter/ExceptionTest.java b/src/test/java/roboter/ExceptionTest.java
new file mode 100644
index 0000000..0fe258b
--- /dev/null
+++ b/src/test/java/roboter/ExceptionTest.java
@@ -0,0 +1,54 @@
+package roboter;
+
+import org.junit.Assert;
+import org.junit.Test;
+import roboter.exceptions.RobotIllegalStateException;
+
+public class ExceptionTest {
+ @Test
+ public void testNexus6Speak(){
+ Nexus6 robot = Nexus6.getInstance();
+ Assert.assertThrows(RobotIllegalStateException.class,()->{
+ robot.speak(new int[]{1,2,3,4});
+ });
+ Assert.assertThrows(RobotIllegalStateException.class,()->{
+ robot.think(new int[]{1,2,3,4});
+ });
+
+
+ }
+ @Test
+ public void powerOffSpeak(){
+ Robot robot=RobotFactory.getRobot(Typ.C3PO,"dfg");
+ robot.triggerPowerSwitch();
+
+ Assert.assertThrows(RobotIllegalStateException.class,()->{
+ robot.speak(new int[8]);
+ });
+ Robot robot2=RobotFactory.getRobot(Typ.R2D2,"dfg");
+ robot2.triggerPowerSwitch();
+ Assert.assertThrows(RobotIllegalStateException.class,()->{
+ robot2.speak(new int[8]);
+ });
+
+ Assert.assertThrows(RobotIllegalStateException.class,()->{
+ robot.think(new int[8]);
+ });
+
+ Assert.assertThrows(RobotIllegalStateException.class,()->{
+ robot2.think(new int[8]);
+ });
+ }
+
+
+
+ @Test
+ public void testNexus6Trigger(){
+ Nexus6 robot = Nexus6.getInstance();
+ boolean isPowerOn = robot.isPowerOn();
+ robot.triggerPowerSwitch();
+ Assert.assertEquals(isPowerOn, robot.isPowerOn());
+ }
+
+
+}
diff --git a/src/test/java/roboter/FactoryTest.java b/src/test/java/roboter/FactoryTest.java
new file mode 100644
index 0000000..f20de78
--- /dev/null
+++ b/src/test/java/roboter/FactoryTest.java
@@ -0,0 +1,30 @@
+package roboter;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class FactoryTest {
+ @Test
+ public void singletonNexus6(){
+ Nexus6 roboter1 = Nexus6.getInstance();
+ Nexus6 roboter2=Nexus6.getInstance();
+ Assert.assertEquals(roboter1,roboter2);
+ }
+ @Test
+ public void factoryMethodTest(){
+ Robot robot1=RobotFactory.getRobot(Typ.R2D2,"roboterX");
+ Assert.assertTrue(robot1 instanceof R2D2);
+ Robot robot2=RobotFactory.getRobot(Typ.C3PO,"roboter2");
+ Assert.assertTrue(robot2 instanceof C3PO);
+
+ Assert.assertEquals(robot1.getName(),"roboterX");
+ Assert.assertEquals(robot2.getName(),"roboter2");
+
+
+ }
+
+
+
+
+
+}
diff --git a/src/test/java/roboter/GetLastExceptionTest.java b/src/test/java/roboter/GetLastExceptionTest.java
new file mode 100644
index 0000000..141c74c
--- /dev/null
+++ b/src/test/java/roboter/GetLastExceptionTest.java
@@ -0,0 +1,44 @@
+package roboter;
+
+import org.junit.Assert;
+import org.junit.Test;
+import roboter.exceptions.RobotIllegalStateException;
+import roboter.exceptions.RobotMagicValueException;
+
+import java.util.ArrayList;
+
+public class GetLastExceptionTest {
+ @Test
+ public void testGetLastExcetion(){
+ int[]zahlen=new int[]{1,3,5,42};
+ Robot robot= RobotFactory.getRobot(Typ.C3PO,"ukzfiouz");
+ Assert.assertThrows(RobotMagicValueException.class,()->{
+ robot.speak(zahlen);
+ });
+ Assert.assertThrows(RobotMagicValueException.class,()->{
+ robot.think(zahlen);
+ });
+ Assert.assertTrue(robot.getLastException() instanceof RobotMagicValueException);
+
+ Robot robot1= RobotFactory.getRobot(Typ.R2D2,"ukzfiouz");
+ Assert.assertThrows(RobotMagicValueException.class,()->{
+ robot1.speak(zahlen);
+ });
+ Assert.assertThrows(RobotMagicValueException.class,()->{
+ robot1.think(zahlen);
+ });
+ Assert.assertTrue(robot1.getLastException() instanceof RobotMagicValueException);
+
+ Robot robot2= RobotFactory.getRobot(Typ.Nexus6,"ukzfiouz");
+ Assert.assertThrows(RobotIllegalStateException.class,()->{
+ robot2.speak(zahlen);
+ });
+ Assert.assertThrows(RobotIllegalStateException.class,()->{
+ robot2.think(zahlen);
+ });
+ Assert.assertTrue(robot2.getLastException() instanceof RobotIllegalStateException);
+ }
+
+
+
+}
diff --git a/src/test/java/roboter/R2D2Test.java b/src/test/java/roboter/R2D2Test.java
new file mode 100644
index 0000000..402aebd
--- /dev/null
+++ b/src/test/java/roboter/R2D2Test.java
@@ -0,0 +1,57 @@
+package roboter;
+
+import org.junit.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DynamicNode;
+import roboter.exceptions.RobotException;
+import roboter.exceptions.RobotMagicValueException;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Properties;
+
+
+
+public class R2D2Test {
+
+
+ @Test
+ public void sortieren() throws RobotException, RobotMagicValueException {
+ var list = new int[]{12,6,7,10,18,2};
+ Robot robot= RobotFactory.getRobot(Typ.R2D2,"roboterX");
+
+ Assert.assertEquals("2,6,7,10,12,18",robot.speak(list));
+
+ var list1 = new int[] {17,10,19,1,4,2,7};
+ Assert.assertEquals("1,2,4,7,10,17,19", robot.speak(list));
+
+ var list2 = new int[] {3,17,7,20,5,15,8};
+ Assert.assertEquals("3,5,7,8,15,17,20", robot.speak(list));
+
+ var list3 = new int[] {13,8,5,12,1,9,7};
+ Assert.assertEquals("1,5,7,8,9,12,13", robot.speak(list));
+
+ var list4 = new int[] {18,4,21,7,3,2,9};
+ Assert.assertEquals("2,3,4,7,9,18,21", robot.speak(list));
+
+ var list5 = new int[] {13,23,8,4,22,6};
+ Assert.assertEquals("4,6,8,13,22,23", robot.speak(list));
+
+ var list6 = new int[] {10,9,8,7,6,5};
+ Assert.assertEquals("5,6,7,8,9,10", robot.speak(list));
+
+ var list7 = new int[] {1,2,3,5,4,6};
+ Assert.assertEquals("1,2,3,4,5,6", robot.speak(list));
+
+ var list8 = new int[] {20,19,18,17,16,15};
+ Assert.assertEquals("15,16,17,18,19,20", robot.speak(list));
+
+ var list9 = new int[] {15,1,13,10,7,4};
+ Assert.assertEquals("1,4,7,10,13,15", robot.speak(list));
+
+ var list10 = new int[] {10,15,11,8,5,6,};
+ Assert.assertEquals("5,6,8,10,11,15", robot.speak(list));
+ }
+
+}
diff --git a/src/tpe/exceptions/roboter/exceptions/RobotException.java b/src/tpe/exceptions/roboter/exceptions/RobotException.java
deleted file mode 100644
index 435b2ed..0000000
--- a/src/tpe/exceptions/roboter/exceptions/RobotException.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package tpe.exceptions.roboter.exceptions;
-
-public class RobotException extends Exception{
-}
diff --git a/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java b/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java
deleted file mode 100644
index 788ecf5..0000000
--- a/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package tpe.exceptions.roboter.exceptions;
-
-public class RobotIllegalStateException {
-}
diff --git a/src/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java b/src/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java
deleted file mode 100644
index 922fdd0..0000000
--- a/src/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package tpe.exceptions.roboter.exceptions;
-
-public class RobotMagicValueException {
-}