diff --git a/Main.java b/Main.java index 3ed5b96..aeb5dd5 100644 --- a/Main.java +++ b/Main.java @@ -28,10 +28,10 @@ public class Main { System.out.print(" " + sorted[i]); } }catch(RobotException re){ - System.out.println(re); + re.printStackTrace(); } - + System.out.println("last exception thrown"); String re = Herb.getLastException().toString(); System.out.println(re); @@ -43,8 +43,9 @@ public class Main { System.out.print(" " + sorted[i]); } }catch(RobotException e){ - System.out.println(e); + e.getLocalizedMessage(); } + System.out.println("last exception thrown"); re = Herb.getLastException().toString(); System.out.println(re); diff --git a/domain/C3PO.java b/domain/C3PO.java index 53ad85d..5eaa36b 100644 --- a/domain/C3PO.java +++ b/domain/C3PO.java @@ -1,5 +1,6 @@ package domain; +import robot.exceptions.ExceptionStorage; import robot.exceptions.RobotException; import robot.exceptions.robotExceptions; @@ -11,16 +12,16 @@ public class C3PO extends RobotBasics { super(id, name); } -// public String ausgabe(int[] input) throws RobotException{ -// if(input.length != 0 && !checkArray(input)){ -// return Arrays.stream(input) -// .mapToObj(Integer::toString) -// .collect(Collectors.joining("; ")); -// }else{ -// throw new RobotException(robotExceptions.MAGICVALUE, getName()); -// // throw new RobotMagicValueException(getName() + " has an unknown Error. Code 42."); -// } -// } +/* public String ausgabe(int[] input) throws RobotException{ + if(input.length != 0 && !checkArray(input)){ + return Arrays.stream(input) + .mapToObj(Integer::toString) + .collect(Collectors.joining("; ")); + }else{ + throw new RobotException(robotExceptions.MAGICVALUE, getName()); + // throw new RobotMagicValueException(getName() + " has an unknown Error. Code 42."); + } + }*/ @Override public String speak(int[] input) throws RobotException { if(isPowerOn()){ @@ -30,24 +31,21 @@ public class C3PO extends RobotBasics { return re.toString(); } }else{ - throw new RobotException(robotExceptions.ILLEGALSTATE, getName()); - //throw new RobotIllegalStateException(getName() + " is turned off."); + RobotException robotException = new RobotException(robotExceptions.ILLEGALSTATE, getName()); + this.exceptions = new ExceptionStorage(robotException); + throw robotException; } } public int[] sorting(int[] input) throws RobotException{ - if(input.length != 0 ){ if(checkArray(input)){ return insertionSort(input); }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[] input) throws RobotException { //Insertionsort diff --git a/domain/R2D2.java b/domain/R2D2.java index bc8a856..b7f6441 100644 --- a/domain/R2D2.java +++ b/domain/R2D2.java @@ -16,58 +16,32 @@ public class R2D2 extends RobotBasics { } + + /** + * @see robot.interfaces.RobotInstructions + */ public int[] think(int[] input) throws RobotException { if(isPowerOn()){ return selectionSort(input); }else{ - this.exceptions = new ExceptionStorage( new RobotException(robotExceptions.ILLEGALSTATE, getName())); - throw new RobotException(robotExceptions.ILLEGALSTATE, getName()); + RobotException robotexception = new RobotException(robotExceptions.ILLEGALSTATE, getName()); + this.exceptions = new ExceptionStorage(robotexception); + throw robotexception; } } - /* - * this method sorts - * @param input - * @return integer array - * @throws RobotException - - public int[] sorting(int[] input) throws RobotException { - if(checkArray(input)){ - //Selectionsort - int small; - for (int i = 0; i = 0 && input[b] > key) input[b + 1] = input[b--]; + input[b + 1] = key; + } + return input; + }else{ + RobotException robotexception = new RobotException(robotExceptions.MAGICVALUE, getName()); + this.exceptions = new ExceptionStorage(robotexception); + throw robotexception; + } - } + } /** * Sorts any given array of integers with the selection Sort algorithm. @@ -152,9 +161,12 @@ public abstract class RobotBasics implements Robot { } return input; }else{ - this.exceptions = new ExceptionStorage(new RobotException(robotExceptions.MAGICVALUE, getName())); - throw new RobotException(robotExceptions.MAGICVALUE, getName()); + RobotException robotexception = new RobotException(robotExceptions.MAGICVALUE, getName()); + this.exceptions = new ExceptionStorage(robotexception); + throw robotexception; } } + + } diff --git a/out/production/Robot_Factory_PR/Main.class b/out/production/Robot_Factory_PR/Main.class index 813b4d7..2afee34 100644 Binary files a/out/production/Robot_Factory_PR/Main.class and b/out/production/Robot_Factory_PR/Main.class differ diff --git a/out/production/Robot_Factory_PR/classpath.index b/out/production/Robot_Factory_PR/classpath.index new file mode 100644 index 0000000..03ee4a3 Binary files /dev/null and b/out/production/Robot_Factory_PR/classpath.index differ diff --git a/out/production/Robot_Factory_PR/domain/C3PO.class b/out/production/Robot_Factory_PR/domain/C3PO.class index 4c06df2..241c8f0 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/C3POTest.class b/out/production/Robot_Factory_PR/domain/C3POTest.class index 0788cbc..81076ce 100644 Binary files a/out/production/Robot_Factory_PR/domain/C3POTest.class and b/out/production/Robot_Factory_PR/domain/C3POTest.class differ diff --git a/out/production/Robot_Factory_PR/domain/R2D2.class b/out/production/Robot_Factory_PR/domain/R2D2.class index 485d9ab..4668be1 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 f5b0081..28b7021 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/robot/exceptions/RobotException$1.class b/out/production/Robot_Factory_PR/robot/exceptions/RobotException$1.class index 3c73d7b..a93d60e 100644 Binary files a/out/production/Robot_Factory_PR/robot/exceptions/RobotException$1.class 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 c4d701e..6e265cf 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/robot/exceptions/RobotException.java b/robot/exceptions/RobotException.java index ada4428..8c2587f 100644 --- a/robot/exceptions/RobotException.java +++ b/robot/exceptions/RobotException.java @@ -2,8 +2,10 @@ package robot.exceptions; public class RobotException extends Exception{ robotExceptions currentType; + String name; public RobotException(robotExceptions type, String name){ super(getMessage(type, name)); + this.name = name; this.currentType = type; } @@ -18,5 +20,10 @@ public class RobotException extends Exception{ return message; } + @Override + public String toString(){ + return getMessage(this.currentType, this.name); + } + }