diff --git a/Main.java b/Main.java index 5ee4902..0b35a7d 100644 --- a/Main.java +++ b/Main.java @@ -1,18 +1,25 @@ -import domain.C3PO; +import domain.*; import robot.exceptions.RobotException; public class Main { public static void main(String[] args) { - C3PO Herbert = new C3PO(0, "Herbert"); - R2D2 Gudrun = new R2D2(0, "Gdurun"); - int[] input = {6,5,4,3,2,1}; + + int[] input = {42,6,5,4,3,2,1}; int[] input2 = input; + C3PO Herbert = new C3PO(1, "Herbert"); + R2D2 Herb = new R2D2(0, "Herb"); + //Herbert.triggerPowerSwitch(); - //Gudrun.triggerPowerSwitch(); - + Herb.triggerPowerSwitch(); + try{ + String array = Herb.speak(input); + System.out.println(array); + } catch (RobotException e) { + System.out.println(e); + } //System.out.println("Was neues ausgeben"); //just some testing diff --git a/domain/C3PO.java b/domain/C3PO.java index 2339858..946bb31 100644 --- a/domain/C3PO.java +++ b/domain/C3PO.java @@ -1,20 +1,45 @@ package domain; import robot.exceptions.RobotException; -import robot.interfaces.Sorting; +import robot.exceptions.RobotIllegalStateException; +import robot.exceptions.RobotMagicValueException; + +import java.util.Arrays; +import java.util.stream.Collectors; + public class C3PO extends RobotBasics { public C3PO(int id, String name){ 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 RobotMagicValueException(getName() + " has an unknown Error. Code 42."); + } + } + @Override + public String speak(int[] zahlen) throws RobotException { + //Insertionsort + if(isPowerOn()){ + try{ + return ausgabe(zahlen); + }catch(RobotException re){ + return re.toString(); + } + }else{ + throw new RobotIllegalStateException(getName() + " is turned off."); + } + + } @Override public int[] think(int[] zahlen) throws RobotException { - return insertionSort.sorting(zahlen); + return new int[0]; } - - Sorting insertionSort = (int[] input) ->{ - System.out.println("ich sortiere mit insertion-Sort"); - return input; - }; - } + + + diff --git a/domain/C3POTest.java b/domain/C3POTest.java index 49c1359..23fa4d8 100644 --- a/domain/C3POTest.java +++ b/domain/C3POTest.java @@ -5,7 +5,7 @@ import static org.junit.jupiter.api.Assertions.*; class C3POTest { - C3PO Herbert; + C3PO Herbert; int id = 0; String name = "Herbert"; diff --git a/domain/R2D2.java b/domain/R2D2.java index 2433b74..aa3d424 100644 --- a/domain/R2D2.java +++ b/domain/R2D2.java @@ -3,20 +3,38 @@ package domain; 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; public class R2D2 extends RobotBasics { /** - * Constructor - @@ -8,7 +12,35 @@ public class R2D2 extends RobotBasics { + * + * @param id> int + * @param name> String */ public R2D2(int id, String name){ super(id, name); } - @Override + /*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 { if(isPowerOn()){ - return sorting(zahlen); + return sorting(zahlen); }else{ throw new RobotIllegalStateException(getName() + " is turned off!"); } @@ -41,16 +59,15 @@ public class R2D2 extends RobotBasics { return arr; } - public String ausgabe(int[] input){ - String result = " "; - if(input.length != 0) { - result = " " + input[0]; - for(int i = 1; i < input.length; i++){ - result += "; " + input[i]; - } - return result; + // Diese ganze Methode muss zu C3P0 und ist hier falsch. + 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 RobotMagicValueException(getName() +" has an unknown Error. Code 42."); } - return null; } /** @@ -61,10 +78,21 @@ public class R2D2 extends RobotBasics { */ @Override public String speak(int[] input) throws RobotException { - if(isPowerOn()){ - return ausgabe(input); - }else{ + final boolean[] found_42 = {false}; + if (isPowerOn()) { + try{ + return ausgabe(input); + }catch(RobotException re){ + return re.toString(); + } + + } else { throw new RobotIllegalStateException(getName() + " is turned off!"); + } + + /*public void something() { + System.out.println("Hello"); + }*/ } } \ No newline at end of file diff --git a/domain/R2D2Test.java b/domain/R2D2Test.java index 93b874d..f84f794 100644 --- a/domain/R2D2Test.java +++ b/domain/R2D2Test.java @@ -2,10 +2,7 @@ package domain; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; class R2D2Test { @@ -21,6 +18,7 @@ class R2D2Test { //Tests for basic functions @Test void getId() { + assertEquals(id, Herbert.getId()); } diff --git a/domain/RobotBasics.java b/domain/RobotBasics.java index 1fa9248..c016e67 100644 --- a/domain/RobotBasics.java +++ b/domain/RobotBasics.java @@ -7,7 +7,7 @@ import robot.interfaces.Robot; import java.util.Arrays; -public class RobotBasics implements Robot { +public abstract class RobotBasics implements Robot { private int id; private String name; private boolean power; @@ -38,10 +38,10 @@ public class RobotBasics implements Robot { */ @Override public void triggerPowerSwitch() { - if(power == false){ - power = true; - }else{ + if(power){ power = false; + }else{ + power = true; } } @@ -61,32 +61,13 @@ public class RobotBasics implements Robot { return null; } - /** - * @see robot.interfaces.RobotInstructions; - * Maybe method is depractable - */ - @Override - public String speak(int[] zahlen) throws RobotException { - if(isPowerOn() == true){ - final String[] array = {""}; - Arrays.stream(zahlen).forEach(i -> array[0] += i + ", "); - return array[0]; - }else{ - throw new RobotIllegalStateException( name + " is turned off."); + public boolean checkArray(int[] input){ + for(int x: input){ + if(x == 42){ + return true; + } } - } - /** - * @see robot.interfaces.RobotInstructions - * Maybe method is depractable - */ - @Override - public int[] think(int[] zahlen) throws RobotException { - if(isPowerOn() == true){ - return zahlen; - }else{ - throw new RobotIllegalStateException(name + " is turned off"); - } - + return false; } } diff --git a/facade/Factory.java b/facade/Factory.java index ad77430..b990d22 100644 --- a/facade/Factory.java +++ b/facade/Factory.java @@ -1,4 +1,5 @@ package facade; public class Factory { + } diff --git a/makefile b/makefile index 4884dfb..96962c2 100644 --- a/makefile +++ b/makefile @@ -11,8 +11,10 @@ update_all: git add --all git commit -m "Updated everything. Further explanation in README" git push -u origin main - update_domain: git add domain/ git commit -m "Updated domain. Further explanation in README" - git push -u origin main \ No newline at end of file + 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/Main.class b/out/production/Robot_Factory_PR/Main.class index ced57d2..7070d90 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/domain/C3PO.class b/out/production/Robot_Factory_PR/domain/C3PO.class index 99b29ad..c81272f 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 f2ce9b6..e0fed2a 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/R2D2Test.class b/out/production/Robot_Factory_PR/domain/R2D2Test.class index f678611..4db2b49 100644 Binary files a/out/production/Robot_Factory_PR/domain/R2D2Test.class and b/out/production/Robot_Factory_PR/domain/R2D2Test.class differ diff --git a/out/production/Robot_Factory_PR/domain/RobotBasics.class b/out/production/Robot_Factory_PR/domain/RobotBasics.class index d4faba1..2e6d341 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 4884dfb..96962c2 100644 --- a/out/production/Robot_Factory_PR/makefile +++ b/out/production/Robot_Factory_PR/makefile @@ -11,8 +11,10 @@ update_all: git add --all git commit -m "Updated everything. Further explanation in README" git push -u origin main - update_domain: git add domain/ git commit -m "Updated domain. Further explanation in README" - git push -u origin main \ No newline at end of file + 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/interfaces/Sorting.class b/out/production/Robot_Factory_PR/robot/interfaces/Sorting.class deleted file mode 100644 index 06950b3..0000000 Binary files a/out/production/Robot_Factory_PR/robot/interfaces/Sorting.class and /dev/null differ diff --git a/robot/interfaces/Sorting.java b/robot/interfaces/Sorting.java deleted file mode 100644 index 7efee17..0000000 --- a/robot/interfaces/Sorting.java +++ /dev/null @@ -1,7 +0,0 @@ -package robot.interfaces; - -@FunctionalInterface -public interface Sorting { - int[] sorting(int[] input); - -}