From b691e40c56cdc1932bbb990386a9b13aab6385d7 Mon Sep 17 00:00:00 2001 From: Philipp3107 Date: Tue, 20 Dec 2022 12:03:41 +0100 Subject: [PATCH] Updated everything. Further explanation in README --- Main.java | 19 ++++-- domain/C3PO.java | 41 +++++++++--- domain/C3POTest.java | 2 +- domain/R2D2.java | 60 +++++++++++++----- domain/R2D2Test.java | 6 +- domain/RobotBasics.java | 39 +++--------- facade/Factory.java | 1 + makefile | 6 +- out/production/Robot_Factory_PR/Main.class | Bin 1075 -> 1110 bytes .../Robot_Factory_PR/domain/C3PO.class | Bin 1379 -> 607 bytes .../Robot_Factory_PR/domain/R2D2.class | Bin 1884 -> 2967 bytes .../Robot_Factory_PR/domain/R2D2Test.class | Bin 1329 -> 1329 bytes .../Robot_Factory_PR/domain/RobotBasics.class | Bin 2767 -> 1170 bytes out/production/Robot_Factory_PR/makefile | 6 +- .../robot/interfaces/Sorting.class | Bin 213 -> 0 bytes robot/interfaces/Sorting.java | 7 -- 16 files changed, 112 insertions(+), 75 deletions(-) delete mode 100644 out/production/Robot_Factory_PR/robot/interfaces/Sorting.class delete mode 100644 robot/interfaces/Sorting.java 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 ced57d29d426ea446a7e6b72a8fd5883e3843fa8..7070d90035d8d9bc4e713e03533239dd8792c584 100644 GIT binary patch delta 644 zcmYjPOHUI~7(I77Gq;^iNi9?;R-qIsw906!A{6lf3qp!Rs7hv~(>kd|EN0S(uGqO_ z(eyv)8co_nj6ZNGCAMlobPeJ%*XJzuyOk1(-#0MSnC*XOX|Ak*9;87 z3}D1W61qU5?Kc|@&)?cV@cimQvt54{(4!{Ckm|h4#3DF{w8VK67ckNJUW#TgC6P5T zjhXI(u*@nuv>N5PM-mr1r&BWqGMEeKyg+icvg^Kbtv$EZua+EqKQVTttUD7^aJf-z8`5v)y-orK?B8L!y1?LeZO5QijT!gC`xP=&1 zXRv_;wMnXnv4asjrpkIv`8o?WSa1#3d4e5!H?TmDFThPK(oSO;ODJ<(j&_-z!q(QH md58nDY`?-+-=;PV?A2e8AZR!M delta 654 zcmY*X+int36kP{q<}kxRkSY{!E%j1pp(wPXU~8?$iUCJ$gBeLQQy>a$X+yv#6W)9$ ze1y+v0*N)g_~r-rAO3*4il&LlWS_OqUTf{WXXc0JlgIe}>+@FtYq;At-iNf!TDRS8 z8Suk2AaUBn8HD=ZqHc-lK~v26bezRGiSs5d;9~!0#yg9s#GHvsxI9RS)V#IRtXDhv zc=_1ms)>2T1k}!(Mr&6 z5vHDhfG?+hL?oh)Fq4QVBV76aZpf*#Sj9TRc!a0e=IO@qoHyWO^uWuxLNKsQltqBt zDY8#t13@Z6)I=t#GN$noG4Ayac*u{wL2()xzLN3@;zBf9p|O`DgG~f23N*gSL6*7t rE#x>rmPUCZ1-HqKLix>}s>G^--DCI&JQd=)(FR3khTi diff --git a/out/production/Robot_Factory_PR/domain/C3PO.class b/out/production/Robot_Factory_PR/domain/C3PO.class index 99b29ad1e5fe7d0ac611b02edf35d9908fea0140..c81272f70a590cb936018d8621a88aecd5524416 100644 GIT binary patch literal 607 zcmZvY%SyvQ6o&svW1`Vouk}(z-KmIO2qGvh6oo)gvC>Uf({#|$b|PsM@u_qri1+|L zl=x3uidX}gbN|le>-+r^z#*0cILP^M$1ns>V5*U{q&DTtq@H9)vaRE`fOnvc&JG2N z>tS>&A7!~I&2_nwrP^HYZ&ZB@3yk(Ek9RK41>EDLp#%z%HtOu5RafbitT*YIijr71 zt1{Kr?m6A;Mzc>o`o-86aCAdJgrphS>eLQ27Z_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UL(9>HMDQuZIO1qz2dj-ZftHj)rNo~-4bydlLDqVrZMwjBysy>K0nlI)##^HMRL@eOGfCuhG7OT^N z@7ZON$z= zhtZ;UK)a9Z0D`m+lea*=kIrbWwQmnBw+{jMgvdLJ)!_{7l6NmrM!Q$xEXCwn4n{Ca z9%bVk&U+kDb%MK1q;tDy@V|wW`-n*IXC&&d^93!76mHw6qS!k!sfO^$|JPihE2F=NwtQr7Y#0;VU delta 87 zcmdnUwUKLs1v4iX0}BH$11AIDWJhLiRzU_~2BFClnS)p*82A_@C)=|qPUd7WWR(T- nky$7`PZTfjlh+X$I}doU9rEVoMCi diff --git a/out/production/Robot_Factory_PR/domain/RobotBasics.class b/out/production/Robot_Factory_PR/domain/RobotBasics.class index d4faba1e6e4d84a684ef77628dc5efde8c3afaba..2e6d34124353a5af1ca057b19f4e0b2fb86f2955 100644 GIT binary patch delta 674 zcmZuuO)qOv6kX@zx@~>6^r9$=(%#lbB20v&BoYH*V#4S}Bu_{y<;63QP9(W8w0W2E ze>k|cw^BIREH38-R4TpZ9jNKy(8kZrjqO~q_~TH(O06%Z*963G##{N_U;6@bebGk7 zE9ky)oj?E*0uB_h9t|ua(TuQAs5_Z>q$Jn&N~> zo%Tzw`ZfWFr6Xskchx;2R|vS8c*|@GG4CkQUNR2KO*oY%`pIa>X3a(hFj%9VNVS*A zn(ZVpR1s&1W)M083?o&Mp3q1grOC`v_Gwm4X-CH|(2;fY=#=GHVfP%C zzCPCC>itETzG#ehd0{!OWsXVb5l4<@7W`snVNtFzP2&@0ugOYX6S>H+vY9~>)Efde PvO+{(xqpEXvJ#^o6&yjZ literal 2767 zcmcImU3U{z6x}yTn>3xaX=sa3g#ZPTG&G2U9{~g^rI8enKoN?{O)^b~CNptn!iWFC zcb8AT`QihvWku^!-(CJDm;264(`lQ9zW6Y6=bn2$_Bm(Yd*{!;H-86k5zmu|AR0$Z z!vF>aQjg^mS!_wOS-e?$tk+$E!SjY`xEBSY+1&CF5*UgjsbLtJK)PYIrC}CtTQ$qQ zA|0dd2t>jFsP5Dv$Y(QpJux3s#h(JEfHZTXzw1|8SdWm_PV zT`A{$Jf4CtFP2T04yjQ}vp_Q%j^hNaWWBC;Sd6pTmAyHH-K=)ax@%abax`z5PPeVw zrD0@|izBaL76pNWUKRRA6^O4|_ElM56F8O)!RzZcw;acuz^tvxU(}x|jEwF0{V2Cu zdQ-Nlu5|UQTWe_uoYwFr&Is&p%XOU~>(aevxN8coD@~VGIuV5Sh~O8v6l56|C2wl?K`s8@~CIkWoud5hMEV$n7d{$+lk6v8Z-JpQ+LaxGI?KSUpTwr zv3MferxYYN3Egb!wnx_LQ^Qp~9AWkA>r1i|L`>03MLKS;AF9o{O8*A-loS}Jqsw)b zd5^Z?a#2Alh70WLLr@aw2-`VW5R1J6y|V`orz;?5{A}0wX`bqBI*V-I=La)_S*7 z+RLVpWQXCM=N&z){@)kLhrUHDz&hbwsXexC=E~OTxh8 zIM&rJYYEKkDV4v8{ms6xRjjZ7|MCQfN0^lU#j@i(*_~yQB&5#)t_~$Ovd<)70(xmUJAQ%@;yZh z&`*q>hA@s%q%$G^dFKE@QkL!y^z)I*YH zl0Xi;6A8b-B<4bnCj(U1s1rkEEJkGf73hO+e0OqZLv99o$t|KB7#BFI%0$HO%r1m1 zBR$KHaGe>c%)TNN)x&f7pD-Ew7Ma*@IB-9jo~|y<{){&Yn>Ysif|C&xqGw+Gic|Ml zf{{&@6EE@BAGGvS_q)764qan^7s;kF|1qw6(N&jK&nsABRK^N$sIMEiN#v>|QHbNX z#Sc}NkNH$_Cjj|~i^_01068!lLUL{wl2IyyrU`Z}iF+P`Dc`&ocY0^s^@*dFk3Kvzy@_{#>Nc@`-Ytd#XkLmm;O4ouv9CdG9aaP$x;Lizj%71OEW0k9#%% 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 06950b3820d49e8a07e35564eab9018183b12122..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 213 zcmYL@y$ZrW5QJx=<}_MZYGtd9_W*)m69@=`0h?5paE1%#9V8bY&cX-qp~Q