diff --git a/Main.java b/Main.java index 0b35a7d..3ed5b96 100644 --- a/Main.java +++ b/Main.java @@ -5,21 +5,49 @@ public class Main { public static void main(String[] args) { - int[] input = {42,6,5,4,3,2,1}; + int[] input = {42,6,5,4,3,43,1}; int[] input2 = input; C3PO Herbert = new C3PO(1, "Herbert"); R2D2 Herb = new R2D2(0, "Herb"); + int[] input3 = {}; //Herbert.triggerPowerSwitch(); - Herb.triggerPowerSwitch(); +// Herb.triggerPowerSwitch(); +// try{ +// String sorted = Herb.speak(input); +// System.out.println(sorted); +// } catch (RobotException re) { +// System.out.println(re); +// } + try{ - String array = Herb.speak(input); - System.out.println(array); - } catch (RobotException e) { + int[] sorted = Herb.think(input); + for(int i = 0; i < sorted.length; i++){ + System.out.print(" " + sorted[i]); + } + }catch(RobotException re){ + System.out.println(re); + } + + + String re = Herb.getLastException().toString(); + System.out.println(re); + + Herb.triggerPowerSwitch(); + + try{ + int[] sorted = Herb.think(input); + for(int i = 0; i < sorted.length; i++){ + System.out.print(" " + sorted[i]); + } + }catch(RobotException e){ System.out.println(e); } + re = Herb.getLastException().toString(); + System.out.println(re); + //System.out.println("Was neues ausgeben"); //just some testing diff --git a/domain/C3PO.java b/domain/C3PO.java index 946bb31..8390c99 100644 --- a/domain/C3PO.java +++ b/domain/C3PO.java @@ -1,8 +1,7 @@ package domain; import robot.exceptions.RobotException; -import robot.exceptions.RobotIllegalStateException; -import robot.exceptions.RobotMagicValueException; +import robot.exceptions.robotExceptions; import java.util.Arrays; import java.util.stream.Collectors; @@ -18,26 +17,46 @@ public class C3PO extends RobotBasics { .mapToObj(Integer::toString) .collect(Collectors.joining("; ")); }else{ - throw new RobotMagicValueException(getName() + " has an unknown Error. Code 42."); + throw new RobotException(robotExceptions.MAGICVALUE, getName()); + // throw new RobotMagicValueException(getName() + " has an unknown Error. Code 42."); } } @Override - public String speak(int[] zahlen) throws RobotException { - //Insertionsort + public String speak(int[] input) throws RobotException { if(isPowerOn()){ try{ - return ausgabe(zahlen); + return ausgabe(input); }catch(RobotException re){ return re.toString(); } }else{ - throw new RobotIllegalStateException(getName() + " is turned off."); + throw new RobotException(robotExceptions.ILLEGALSTATE, getName()); + //throw new RobotIllegalStateException(getName() + " is turned off."); } } + + public int[] sorting(int[] input) throws RobotException{ + if(input.length != 0 ){ + if(checkArray(input)){ + //sort + }else{ + throw new RobotException(robotExceptions.MAGICVALUE, getName()); + //throw new RobotMagicValueException(getName() + " has an unknown error. Code 42"); + } + + } +return new int[0]; + } @Override - public int[] think(int[] zahlen) throws RobotException { - return new int[0]; + public int[] think(int[] input) throws RobotException { + //Insertionsort + if(isPowerOn()){ + return sorting(input); + }else{ + throw new RobotException(robotExceptions.ILLEGALSTATE, getName()); + // throw new RobotIllegalStateException(getName() + " is turned off."); + } } } diff --git a/domain/R2D2.java b/domain/R2D2.java index aa3d424..bc8a856 100644 --- a/domain/R2D2.java +++ b/domain/R2D2.java @@ -1,16 +1,9 @@ package domain; +import robot.exceptions.ExceptionStorage; import robot.exceptions.RobotException; -import robot.exceptions.RobotIllegalStateException; -import robot.exceptions.RobotMagicValueException; - -import java.util.Arrays; -import java.util.List; -import java.util.OptionalInt; -import java.util.function.IntPredicate; -import java.util.stream.Collector; -import java.util.stream.Collectors; +import robot.exceptions.robotExceptions; public class R2D2 extends RobotBasics { /** @@ -22,53 +15,45 @@ public class R2D2 extends RobotBasics { super(id, name); } - /*Sorting sort = (int[] input) -> { - int small; - for(int i = 0; i < input.length -1; i++){ - small = i; - for(int j = i + 1; j < input.length; j++){ - if(input[j] < ) - } - } - }*/ - public int[] think(int[] zahlen) throws RobotException { + public int[] think(int[] input) throws RobotException { if(isPowerOn()){ - return sorting(zahlen); + return selectionSort(input); }else{ - throw new RobotIllegalStateException(getName() + " is turned off!"); + this.exceptions = new ExceptionStorage( new RobotException(robotExceptions.ILLEGALSTATE, getName())); + throw new RobotException(robotExceptions.ILLEGALSTATE, getName()); } } - public int[] sorting(int[] arr) { - //Selectionsort - int small; - for (int i = 0; i Class R2D2 @@ -350,3 +368,9 @@ Textdatei in Ihr Projekt, in der Sie die notwendigen Erweiterungen und evtl. Än * Testen Sie Ihre Implementierung möglichst umfangreich. Wir werden es auf jeden Fall tun. ! * Nutzen Sie für die gemeinsame Arbeit an der Implementierung ein Git-Repository und nutzen Sie regelmäßig. * Es müssen von allen Team-Mitgliedern jeweils mindestens fünf Commits mit substanziellem Inhalt auf den main-Branch gepusht werden. + + + +# Fragen an Hummel + +Was ist mit der Umwandlung von zahlen in arrays den inhalt mit Kommas getrennt gemeint? \ No newline at end of file diff --git a/out/production/Robot_Factory_PR/domain/C3PO.class b/out/production/Robot_Factory_PR/domain/C3PO.class index c81272f..4c06df2 100644 Binary files a/out/production/Robot_Factory_PR/domain/C3PO.class and b/out/production/Robot_Factory_PR/domain/C3PO.class differ diff --git a/out/production/Robot_Factory_PR/domain/R2D2.class b/out/production/Robot_Factory_PR/domain/R2D2.class index e0fed2a..485d9ab 100644 Binary files a/out/production/Robot_Factory_PR/domain/R2D2.class and b/out/production/Robot_Factory_PR/domain/R2D2.class differ diff --git a/out/production/Robot_Factory_PR/domain/RobotBasics.class b/out/production/Robot_Factory_PR/domain/RobotBasics.class index 2e6d341..f5b0081 100644 Binary files a/out/production/Robot_Factory_PR/domain/RobotBasics.class and b/out/production/Robot_Factory_PR/domain/RobotBasics.class differ diff --git a/out/production/Robot_Factory_PR/makefile b/out/production/Robot_Factory_PR/makefile index 96962c2..c4c8eb2 100644 --- a/out/production/Robot_Factory_PR/makefile +++ b/out/production/Robot_Factory_PR/makefile @@ -15,6 +15,13 @@ update_domain: git add domain/ git commit -m "Updated domain. Further explanation in README" git push -u origin main - +update_exceptions: + git add robot/exceptions + git commit -m "Updated Exceptions" + git push -u origin main +update_interfaces: + git add robot/interfaces + git commit -m "updated interfaces" + git push -u origin main fetch_git: git pull origin main \ No newline at end of file diff --git a/out/production/Robot_Factory_PR/robot/exceptions/ArrayEmptyException.class b/out/production/Robot_Factory_PR/robot/exceptions/ArrayEmptyException.class new file mode 100644 index 0000000..a22a604 Binary files /dev/null and b/out/production/Robot_Factory_PR/robot/exceptions/ArrayEmptyException.class differ diff --git a/out/production/Robot_Factory_PR/robot/exceptions/ExceptionStorage.class b/out/production/Robot_Factory_PR/robot/exceptions/ExceptionStorage.class new file mode 100644 index 0000000..5f07ef7 Binary files /dev/null and b/out/production/Robot_Factory_PR/robot/exceptions/ExceptionStorage.class differ diff --git a/out/production/Robot_Factory_PR/robot/exceptions/RobotException$1.class b/out/production/Robot_Factory_PR/robot/exceptions/RobotException$1.class new file mode 100644 index 0000000..3c73d7b Binary files /dev/null and b/out/production/Robot_Factory_PR/robot/exceptions/RobotException$1.class differ diff --git a/out/production/Robot_Factory_PR/robot/exceptions/RobotException.class b/out/production/Robot_Factory_PR/robot/exceptions/RobotException.class index a8a54aa..c4d701e 100644 Binary files a/out/production/Robot_Factory_PR/robot/exceptions/RobotException.class and b/out/production/Robot_Factory_PR/robot/exceptions/RobotException.class differ diff --git a/out/production/Robot_Factory_PR/robot/exceptions/RobotIllegalStateException.class b/out/production/Robot_Factory_PR/robot/exceptions/RobotIllegalStateException.class index c615c5b..e7988e5 100644 Binary files a/out/production/Robot_Factory_PR/robot/exceptions/RobotIllegalStateException.class and b/out/production/Robot_Factory_PR/robot/exceptions/RobotIllegalStateException.class differ diff --git a/out/production/Robot_Factory_PR/robot/exceptions/RobotMagicValueException.class b/out/production/Robot_Factory_PR/robot/exceptions/RobotMagicValueException.class index e142b68..3bc7be9 100644 Binary files a/out/production/Robot_Factory_PR/robot/exceptions/RobotMagicValueException.class and b/out/production/Robot_Factory_PR/robot/exceptions/RobotMagicValueException.class differ diff --git a/out/production/Robot_Factory_PR/robot/exceptions/robotExceptions.class b/out/production/Robot_Factory_PR/robot/exceptions/robotExceptions.class new file mode 100644 index 0000000..55a0bc1 Binary files /dev/null and b/out/production/Robot_Factory_PR/robot/exceptions/robotExceptions.class differ diff --git a/robot/exceptions/ArrayEmptyException.java b/robot/exceptions/ArrayEmptyException.java new file mode 100644 index 0000000..3b3cfdb --- /dev/null +++ b/robot/exceptions/ArrayEmptyException.java @@ -0,0 +1,7 @@ +package robot.exceptions; + +public class ArrayEmptyException extends RobotException{ + public ArrayEmptyException(robotExceptions type,String errorMessage){ + super(type, errorMessage); + } +} diff --git a/robot/exceptions/ExceptionStorage.java b/robot/exceptions/ExceptionStorage.java new file mode 100644 index 0000000..128f4b6 --- /dev/null +++ b/robot/exceptions/ExceptionStorage.java @@ -0,0 +1,35 @@ +package robot.exceptions; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class ExceptionStorage { + private RobotException message; + private LocalDateTime date; + + public ExceptionStorage(RobotException message){ + this.message = message; + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); + LocalDateTime now = LocalDateTime.now(); + this.date = now; + } + + public void saveLatestErrorMessage(RobotException message){ + this.message = message; + this.date = LocalDateTime.now(); + } + + public RobotException getLastErrorMessage(){ + return this.message; + } + + /*public boolean emptyErrorStorage(){ + if(this.message != ""){ + this.message = ""; + this.date = LocalDateTime.now(); + return true; + }else{return false;} + + }*/ + +} diff --git a/robot/exceptions/RobotException.java b/robot/exceptions/RobotException.java index ccbfcb2..ada4428 100644 --- a/robot/exceptions/RobotException.java +++ b/robot/exceptions/RobotException.java @@ -1,8 +1,22 @@ package robot.exceptions; public class RobotException extends Exception{ - public RobotException(String errorMessage){ - super(errorMessage); + robotExceptions currentType; + public RobotException(robotExceptions type, String name){ + super(getMessage(type, name)); + this.currentType = type; + + } + + private static String getMessage(robotExceptions types, String name){ + String message = ""; + switch (types){ + case ILLEGALSTATE: message = name + " is turned off."; break; + case MAGICVALUE: message = name + " has an unknown error. Code 42."; break; + case EMPTYARRAY: message = name + " got an empty array."; break; + } + return message; } } + diff --git a/robot/exceptions/RobotIllegalStateException.java b/robot/exceptions/RobotIllegalStateException.java index 70b0e66..e39128e 100644 --- a/robot/exceptions/RobotIllegalStateException.java +++ b/robot/exceptions/RobotIllegalStateException.java @@ -1,7 +1,8 @@ package robot.exceptions; public class RobotIllegalStateException extends RobotException{ - public RobotIllegalStateException(String errormessage){ - super(errormessage); + + public RobotIllegalStateException(robotExceptions type, String errormessage){ + super(type, errormessage); } } diff --git a/robot/exceptions/RobotMagicValueException.java b/robot/exceptions/RobotMagicValueException.java index b4c8a96..3574087 100644 --- a/robot/exceptions/RobotMagicValueException.java +++ b/robot/exceptions/RobotMagicValueException.java @@ -1,7 +1,8 @@ package robot.exceptions; -public class RobotMagicValueException extends RobotException{ - public RobotMagicValueException(String errormessage){ - super(errormessage); +public class RobotMagicValueException extends RobotException { + public RobotMagicValueException(robotExceptions type, String errormessage) { + super(type, errormessage); } -} + +} \ No newline at end of file diff --git a/robot/exceptions/robotExceptions.java b/robot/exceptions/robotExceptions.java new file mode 100644 index 0000000..656c059 --- /dev/null +++ b/robot/exceptions/robotExceptions.java @@ -0,0 +1,5 @@ +package robot.exceptions; + +public enum robotExceptions { + ILLEGALSTATE, MAGICVALUE, EMPTYARRAY +} diff --git a/robot/interfaces/RobotInstructions.java b/robot/interfaces/RobotInstructions.java index bb83a65..cd9a9e0 100644 --- a/robot/interfaces/RobotInstructions.java +++ b/robot/interfaces/RobotInstructions.java @@ -30,23 +30,23 @@ public interface RobotInstructions { * Gibt ein Array von Zahlen als String zurück. Die Zahlen werden * nicht sortiert. * - * @param zahlen Zahlen, die ausgegeben werden sollen. + * @param numbers Zahlen, die ausgegeben werden sollen. * @return Zahlen als String * @throws RobotException wenn der Roboter in einem ungültigen Zustand ist, * oder das Array nicht seinen Vorstellungen entspricht. */ - String speak(int[] zahlen) throws RobotException; + String speak(int[] numbers) throws RobotException; /** * Sortiert ein Array von Zahlen. Die Reihenfolge hängt von dem Typ des * Roboters ab. * - * @param zahlen Zahlen, die sortiert werden sollen. + * @param numbers Zahlen, die sortiert werden sollen. * @return Sortierte Zahlen * @throws RobotException wenn der Roboter in einem ungültigen Zustand ist, * oder das Array nicht seinen Vorstellungen entspricht. */ - int[] think(int[] zahlen) throws RobotException; + int[] think(int[] numbers) throws RobotException; } \ No newline at end of file