diff --git a/Main.java b/Main.java index e5f8633..023cd66 100644 --- a/Main.java +++ b/Main.java @@ -1,5 +1,5 @@ -import facade.FactorySystem; -import ui.UI; +import src.facade.FactorySystem; +import src.ui.UI; public class Main { public static void main(String[] args) { diff --git a/out/production/Robot_Factory_PR/Main.class b/out/production/Robot_Factory_PR/Main.class index bea4650..2f9982d 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/C3POTest.class b/out/production/Robot_Factory_PR/domain/C3POTest.class deleted file mode 100644 index 5b14853..0000000 Binary files a/out/production/Robot_Factory_PR/domain/C3POTest.class and /dev/null differ diff --git a/out/production/Robot_Factory_PR/domain/Factory.class b/out/production/Robot_Factory_PR/domain/Factory.class deleted file mode 100644 index b5330ad..0000000 Binary files a/out/production/Robot_Factory_PR/domain/Factory.class and /dev/null differ diff --git a/out/production/Robot_Factory_PR/domain/Nexus6.class b/out/production/Robot_Factory_PR/domain/Nexus6.class deleted file mode 100644 index 61c70f9..0000000 Binary files a/out/production/Robot_Factory_PR/domain/Nexus6.class and /dev/null differ diff --git a/out/production/Robot_Factory_PR/domain/Robot$RobotType.class b/out/production/Robot_Factory_PR/domain/Robot$RobotType.class deleted file mode 100644 index 46213d0..0000000 Binary files a/out/production/Robot_Factory_PR/domain/Robot$RobotType.class and /dev/null differ diff --git a/out/production/Robot_Factory_PR/domain/Robot.class b/out/production/Robot_Factory_PR/domain/Robot.class deleted file mode 100644 index bb932ee..0000000 Binary files a/out/production/Robot_Factory_PR/domain/Robot.class and /dev/null differ diff --git a/out/production/Robot_Factory_PR/src/domain/C3PO.class b/out/production/Robot_Factory_PR/src/domain/C3PO.class new file mode 100644 index 0000000..372403a Binary files /dev/null and b/out/production/Robot_Factory_PR/src/domain/C3PO.class differ diff --git a/out/production/Robot_Factory_PR/src/domain/Factory.class b/out/production/Robot_Factory_PR/src/domain/Factory.class new file mode 100644 index 0000000..29dd94c Binary files /dev/null and b/out/production/Robot_Factory_PR/src/domain/Factory.class differ diff --git a/out/production/Robot_Factory_PR/src/domain/Nexus6.class b/out/production/Robot_Factory_PR/src/domain/Nexus6.class new file mode 100644 index 0000000..eb22343 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/domain/Nexus6.class differ diff --git a/out/production/Robot_Factory_PR/src/domain/R2D2.class b/out/production/Robot_Factory_PR/src/domain/R2D2.class new file mode 100644 index 0000000..99e5aab Binary files /dev/null and b/out/production/Robot_Factory_PR/src/domain/R2D2.class differ diff --git a/out/production/Robot_Factory_PR/src/domain/Robot.class b/out/production/Robot_Factory_PR/src/domain/Robot.class new file mode 100644 index 0000000..d139f8c Binary files /dev/null and b/out/production/Robot_Factory_PR/src/domain/Robot.class differ diff --git a/out/production/Robot_Factory_PR/src/domain/RobotType.class b/out/production/Robot_Factory_PR/src/domain/RobotType.class new file mode 100644 index 0000000..d534e96 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/domain/RobotType.class differ diff --git a/out/production/Robot_Factory_PR/src/facade/FactorySystem.class b/out/production/Robot_Factory_PR/src/facade/FactorySystem.class new file mode 100644 index 0000000..bd710b3 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/facade/FactorySystem.class differ diff --git a/out/production/Robot_Factory_PR/src/tests/C3POTest.class b/out/production/Robot_Factory_PR/src/tests/C3POTest.class new file mode 100644 index 0000000..537f003 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/tests/C3POTest.class differ diff --git a/out/production/Robot_Factory_PR/src/ui/UI$1.class b/out/production/Robot_Factory_PR/src/ui/UI$1.class new file mode 100644 index 0000000..851bd42 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/ui/UI$1.class differ diff --git a/out/production/Robot_Factory_PR/src/ui/UI.class b/out/production/Robot_Factory_PR/src/ui/UI.class new file mode 100644 index 0000000..685eb77 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/ui/UI.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/interfaces/Robot.class b/out/production/Robot_Factory_PR/src/utility/interfaces/Robot.class new file mode 100644 index 0000000..39dc03c Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/interfaces/Robot.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/interfaces/RobotControl.class b/out/production/Robot_Factory_PR/src/utility/interfaces/RobotControl.class new file mode 100644 index 0000000..9366ea5 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/interfaces/RobotControl.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/interfaces/RobotInstructions.class b/out/production/Robot_Factory_PR/src/utility/interfaces/RobotInstructions.class new file mode 100644 index 0000000..1c6d5b6 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/interfaces/RobotInstructions.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/robot_exceptions/ArrayEmptyException.class b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/ArrayEmptyException.class new file mode 100644 index 0000000..f6344c7 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/ArrayEmptyException.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/robot_exceptions/ExceptionStorage.class b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/ExceptionStorage.class new file mode 100644 index 0000000..9379318 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/ExceptionStorage.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotException.class b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotException.class new file mode 100644 index 0000000..2137eda Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotException.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotIllegalStateException.class b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotIllegalStateException.class new file mode 100644 index 0000000..2bbc4b0 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotIllegalStateException.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotMagicValueException.class b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotMagicValueException.class new file mode 100644 index 0000000..cbd844a Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/RobotMagicValueException.class differ diff --git a/out/production/Robot_Factory_PR/src/utility/robot_exceptions/robotExceptions.class b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/robotExceptions.class new file mode 100644 index 0000000..3cc34b6 Binary files /dev/null and b/out/production/Robot_Factory_PR/src/utility/robot_exceptions/robotExceptions.class differ diff --git a/out/production/Robot_Factory_PR/test_factoryFactory.ser b/out/production/Robot_Factory_PR/test_factoryFactory.ser deleted file mode 100644 index 45cdbe0..0000000 Binary files a/out/production/Robot_Factory_PR/test_factoryFactory.ser and /dev/null differ diff --git a/out/production/Robot_Factory_PR/domain/R2D2Test.class b/out/production/Robot_Factory_PR/tests/R2D2Test.class similarity index 58% rename from out/production/Robot_Factory_PR/domain/R2D2Test.class rename to out/production/Robot_Factory_PR/tests/R2D2Test.class index 4db2b49..6bde74e 100644 Binary files a/out/production/Robot_Factory_PR/domain/R2D2Test.class and b/out/production/Robot_Factory_PR/tests/R2D2Test.class differ diff --git a/out/production/Robot_Factory_PR/ui/UI.class b/out/production/Robot_Factory_PR/ui/UI.class deleted file mode 100644 index a53d4f5..0000000 Binary files a/out/production/Robot_Factory_PR/ui/UI.class and /dev/null differ diff --git a/domain/C3PO.java b/src/domain/C3PO.java similarity index 79% rename from domain/C3PO.java rename to src/domain/C3PO.java index 48221b4..b244aec 100644 --- a/domain/C3PO.java +++ b/src/domain/C3PO.java @@ -1,15 +1,19 @@ -package domain; +package src.domain; -import utility.robot_exceptions.ExceptionStorage; -import utility.robot_exceptions.RobotException; -import utility.robot_exceptions.robotExceptions; +import src.utility.robot_exceptions.ExceptionStorage; +import src.utility.robot_exceptions.RobotException; +import src.utility.robot_exceptions.robotExceptions; public class C3PO extends Robot { public C3PO(int id, String name){ super(id, name, RobotType.C3PO); } - //returns the sorted list as String with the delimiter ';' + /** + * @param input from the user + * @return the sorted list as String with the delimiter ';' + * @throws RobotException + */ @Override public String speak(int[] input) throws RobotException { if(isPowerOn()){ @@ -45,9 +49,13 @@ public class C3PO extends Robot { this.exceptions = new ExceptionStorage(robotexception); throw robotexception; } - } - //Sorting then returning the input arr with insertion Sort + + /** + * @param input + * @return the input arr after insertion Sort + * @throws RobotException + */ @Override public int[] think(int[] input) throws RobotException { if(isPowerOn()){ @@ -58,7 +66,4 @@ public class C3PO extends Robot { throw robotException; } } -} - - - +} \ No newline at end of file diff --git a/domain/Factory.java b/src/domain/Factory.java similarity index 67% rename from domain/Factory.java rename to src/domain/Factory.java index 18d9b9f..6b9a45a 100644 --- a/domain/Factory.java +++ b/src/domain/Factory.java @@ -1,4 +1,4 @@ -package domain; +package src.domain; import java.io.Serializable; import java.util.Collection; @@ -13,13 +13,15 @@ public class Factory implements Serializable { public Factory(){ } - - //Has to return Collection + /** + * @return Collection + */ public Collection robotListToCollection(){ return robots.values(); } - - //return a String arr with robot attributes + /** + * @return a String arr with robot attributes + */ public String[] getRobotList() { Collection collect = robotListToCollection(); String[] list = new String[collect.size()]; @@ -29,12 +31,16 @@ public class Factory implements Serializable { } return list; } - //creates a new robot - public boolean buildNewRobot(String name, int type){ - Robot r ; - if(type == 0) { + /** + * @param name + * @param type + * @return created or not + */ + public boolean buildNewRobot(String name, RobotType type){ + Robot r; + if(type == RobotType.R2D2) { r = new R2D2(r2d2ID++, name); - } else if(type == 1) { + } else if(type == RobotType.C3PO) { r = new C3PO(c3poID++, name); } else { return false; @@ -43,7 +49,10 @@ public class Factory implements Serializable { robots.put(r.getId(), r); return true; } - //returns a specific robot via id + /** + * @param id + * @return a specific robot via id + */ public Robot getRobotOfList(int id){ return robots.get(id); } diff --git a/domain/Nexus6.java b/src/domain/Nexus6.java similarity index 55% rename from domain/Nexus6.java rename to src/domain/Nexus6.java index bb4f6bc..082acef 100644 --- a/domain/Nexus6.java +++ b/src/domain/Nexus6.java @@ -1,29 +1,35 @@ -package domain; - -import utility.robot_exceptions.ExceptionStorage; -import utility.robot_exceptions.RobotException; -import utility.robot_exceptions.robotExceptions; +package src.domain; +import src.utility.robot_exceptions.ExceptionStorage; +import src.utility.robot_exceptions.RobotException; +import src.utility.robot_exceptions.robotExceptions; public final class Nexus6 extends Robot { private static final Nexus6 INSTANCE = new Nexus6(); private Nexus6() { - super(1, "Nexus-6", "Nexus-6"); + super(1, "Nexus-6", RobotType.Nexus6); } public static Nexus6 getInstance() { return INSTANCE; } - - //This method always throws an Illegalstate exception + /** + * This method always throws an Illegalstate exception + * @param numbers Zahlen, die ausgegeben werden sollen. + * @throws RobotException + */ @Override public String speak(int[] numbers) throws RobotException { RobotException e = new RobotException(robotExceptions.ILLEGALSTATE, getName()); this.exceptions = new ExceptionStorage(e); throw e; } - //This method always throws an Illegalstate exception + /** + * This method always throws an Illegalstate exception + * @param numbers Zahlen, die sortiert werden sollen. + * @throws RobotException + */ @Override public int[] think(int[] numbers) throws RobotException { RobotException e = new RobotException(robotExceptions.ILLEGALSTATE, getName()); diff --git a/domain/R2D2.java b/src/domain/R2D2.java similarity index 85% rename from domain/R2D2.java rename to src/domain/R2D2.java index 747cde3..0d033db 100644 --- a/domain/R2D2.java +++ b/src/domain/R2D2.java @@ -1,9 +1,9 @@ -package domain; +package src.domain; - -import utility.robot_exceptions.ExceptionStorage; -import utility.robot_exceptions.RobotException; -import utility.robot_exceptions.robotExceptions; +import src.utility.interfaces.RobotInstructions; +import src.utility.robot_exceptions.ExceptionStorage; +import src.utility.robot_exceptions.RobotException; +import src.utility.robot_exceptions.robotExceptions; public class R2D2 extends Robot { /** @@ -15,7 +15,7 @@ public class R2D2 extends Robot { } /** - * @see utility.interfaces.RobotInstructions + * @see RobotInstructions * Sorting then returning the input arr with selection sort */ public int[] think(int[] input) throws RobotException { @@ -31,7 +31,7 @@ public class R2D2 extends Robot { /** * Sorts any given array of integers with the selection Sort algorithm. * @param input - * @return + * @return an sorted list * @throws RobotException */ public int[] selectionSort(int[] input) throws RobotException{ @@ -57,7 +57,7 @@ public class R2D2 extends Robot { } /** - * @see utility.interfaces.RobotInstructions + * @see RobotInstructions * returns the sorted list as String with the delimiter ',' */ @Override diff --git a/domain/Robot.java b/src/domain/Robot.java similarity index 73% rename from domain/Robot.java rename to src/domain/Robot.java index 1bef763..75669b0 100644 --- a/domain/Robot.java +++ b/src/domain/Robot.java @@ -1,19 +1,16 @@ -package domain; +package src.domain; -import utility.robot_exceptions.ExceptionStorage; -import utility.robot_exceptions.RobotException; -import utility.robot_exceptions.robotExceptions; +import src.utility.robot_exceptions.ExceptionStorage; +import src.utility.robot_exceptions.RobotException; +import src.utility.robot_exceptions.robotExceptions; import java.io.Serializable; import java.util.Arrays; import java.util.stream.Collectors; -public abstract class Robot implements utility.interfaces.Robot, Serializable { - // ENUMS für Robot Type - static enum RobotType { - C3PO, R2D2, Nexus6; - } +public abstract class Robot implements src.utility.interfaces.Robot, Serializable { + protected ExceptionStorage exceptions; private int id; private final String name; @@ -30,7 +27,7 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable { } /** - * @see utility.interfaces.RobotControl; + * @see RobotControl ; */ @Override public int getId() { @@ -38,7 +35,7 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable { } /** - * @see utility.interfaces.RobotControl; + * @see RobotControl ; */ @Override public String getName() { @@ -46,7 +43,7 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable { } /** - * @see utility.interfaces.RobotControl; + * @see RobotControl ; */ @Override public void triggerPowerSwitch() { @@ -54,7 +51,7 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable { } /** - * @see utility.interfaces.RobotControl; + * @see RobotControl ; */ @Override public boolean isPowerOn() { @@ -62,7 +59,7 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable { } /** - * @see utility.interfaces.RobotControl; + * @see RobotControl ; */ @Override public RobotException getLastException() { @@ -79,12 +76,12 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable { * @return boolean * @throws RobotException EMPTYARRAY Exception */ - - // Check lists for the forbidden Number 42 public boolean checkArray(int[] input) throws RobotException{ if(input.length != 0){ - for(int x: input){ - if(x == 42){ return false; } + if (Arrays.stream(input).anyMatch(i -> i == 42)) { + RobotException robotexception = new RobotException(robotExceptions.MAGICVALUE, getName()); + this.exceptions = new ExceptionStorage(robotexception); + throw robotexception; } return true; }else{ @@ -100,8 +97,6 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable { * @return String (array as String) * @throws RobotException */ - - // Write an array with a delimiter to the command line public String output(int[] input, String delemiter)throws RobotException{ if(checkArray(input)) { return Arrays.stream(input) @@ -113,14 +108,17 @@ public abstract class Robot implements utility.interfaces.Robot, Serializable { throw robotexception; } } - public String getType(){ - return this.type.toString(); + + public RobotType getType(){ + return this.type; } - // Override the to String method to get a clean looking outcome + /** + * Override the to String method to get a clean looking outcome + * @return {@link String} + */ @Override public String toString(){ - return "Name: " + name + "; ID: " + id + "; Type: " + type; + return "Name: " + name + "; ID: " + id + "; Type: " + type.toString(); } - } diff --git a/src/domain/RobotType.java b/src/domain/RobotType.java new file mode 100644 index 0000000..04ec47e --- /dev/null +++ b/src/domain/RobotType.java @@ -0,0 +1,14 @@ +package src.domain; + +public enum RobotType { + C3PO("C3PO"), R2D2("R2D2"), Nexus6("Nexus6"); + private final String type; + private RobotType(String type) { + this.type = type; + } + + @Override + public String toString() { + return type; + } +} diff --git a/facade/FactorySystem.java b/src/facade/FactorySystem.java similarity index 81% rename from facade/FactorySystem.java rename to src/facade/FactorySystem.java index 1d3dc97..02c603e 100644 --- a/facade/FactorySystem.java +++ b/src/facade/FactorySystem.java @@ -1,8 +1,8 @@ -package facade; - -import domain.Factory; -import domain.Robot; +package src.facade; +import src.domain.Factory; +import src.domain.Robot; +import src.domain.RobotType; import infrastructure.Persistenz; public class FactorySystem { @@ -26,12 +26,14 @@ public class FactorySystem { } - //provide robot attributes + /** + * @return all Robots + */ public String[] getAllRobots(){ return factory.getRobotList(); } //Creating a new robot - public boolean buildNewRobot(String name, int type) { + public boolean buildNewRobot(String name, RobotType type) { boolean check = factory.buildNewRobot(name, type); if(check) { try { @@ -42,7 +44,11 @@ public class FactorySystem { } return check; } - //provides a specific robot + /** + * + * @param id + * @return a specific robot + */ public Robot searchForRobot(int id){ return factory.getRobotOfList(id); } diff --git a/infrastructure/Persistenz.java b/src/infrastructure/Persistenz.java similarity index 100% rename from infrastructure/Persistenz.java rename to src/infrastructure/Persistenz.java diff --git a/out/production/Robot_Factory_PR/domain/C3PO.class b/src/out/production/Robot_Factory_PR/domain/C3PO.class similarity index 95% rename from out/production/Robot_Factory_PR/domain/C3PO.class rename to src/out/production/Robot_Factory_PR/domain/C3PO.class index 41e78bc..4e45319 100644 Binary files a/out/production/Robot_Factory_PR/domain/C3PO.class and b/src/out/production/Robot_Factory_PR/domain/C3PO.class differ diff --git a/src/out/production/Robot_Factory_PR/domain/Factory.class b/src/out/production/Robot_Factory_PR/domain/Factory.class new file mode 100644 index 0000000..4767b0a Binary files /dev/null and b/src/out/production/Robot_Factory_PR/domain/Factory.class differ diff --git a/out/production/Robot_Factory_PR/domain/R2D2.class b/src/out/production/Robot_Factory_PR/domain/R2D2.class similarity index 95% rename from out/production/Robot_Factory_PR/domain/R2D2.class rename to src/out/production/Robot_Factory_PR/domain/R2D2.class index 0528945..31cb8c2 100644 Binary files a/out/production/Robot_Factory_PR/domain/R2D2.class and b/src/out/production/Robot_Factory_PR/domain/R2D2.class differ diff --git a/src/out/production/Robot_Factory_PR/domain/Robot.class b/src/out/production/Robot_Factory_PR/domain/Robot.class new file mode 100644 index 0000000..0c5199c Binary files /dev/null and b/src/out/production/Robot_Factory_PR/domain/Robot.class differ diff --git a/out/production/Robot_Factory_PR/facade/FactorySystem.class b/src/out/production/Robot_Factory_PR/facade/FactorySystem.class similarity index 79% rename from out/production/Robot_Factory_PR/facade/FactorySystem.class rename to src/out/production/Robot_Factory_PR/facade/FactorySystem.class index 409ab59..f510c18 100644 Binary files a/out/production/Robot_Factory_PR/facade/FactorySystem.class and b/src/out/production/Robot_Factory_PR/facade/FactorySystem.class differ diff --git a/src/out/production/Robot_Factory_PR/infrastructure/Persistenz.class b/src/out/production/Robot_Factory_PR/infrastructure/Persistenz.class new file mode 100644 index 0000000..92e6b24 Binary files /dev/null and b/src/out/production/Robot_Factory_PR/infrastructure/Persistenz.class differ diff --git a/src/out/production/Robot_Factory_PR/ui/UI.class b/src/out/production/Robot_Factory_PR/ui/UI.class new file mode 100644 index 0000000..6c3769f Binary files /dev/null and b/src/out/production/Robot_Factory_PR/ui/UI.class differ diff --git a/out/production/Robot_Factory_PR/utility/interfaces/Robot.class b/src/out/production/Robot_Factory_PR/utility/interfaces/Robot.class similarity index 66% rename from out/production/Robot_Factory_PR/utility/interfaces/Robot.class rename to src/out/production/Robot_Factory_PR/utility/interfaces/Robot.class index c5ef463..67fb5dc 100644 Binary files a/out/production/Robot_Factory_PR/utility/interfaces/Robot.class and b/src/out/production/Robot_Factory_PR/utility/interfaces/Robot.class differ diff --git a/out/production/Robot_Factory_PR/utility/interfaces/RobotControl.class b/src/out/production/Robot_Factory_PR/utility/interfaces/RobotControl.class similarity index 71% rename from out/production/Robot_Factory_PR/utility/interfaces/RobotControl.class rename to src/out/production/Robot_Factory_PR/utility/interfaces/RobotControl.class index 6db39f0..86dccf8 100644 Binary files a/out/production/Robot_Factory_PR/utility/interfaces/RobotControl.class and b/src/out/production/Robot_Factory_PR/utility/interfaces/RobotControl.class differ diff --git a/out/production/Robot_Factory_PR/utility/interfaces/RobotInstructions.class b/src/out/production/Robot_Factory_PR/utility/interfaces/RobotInstructions.class similarity index 68% rename from out/production/Robot_Factory_PR/utility/interfaces/RobotInstructions.class rename to src/out/production/Robot_Factory_PR/utility/interfaces/RobotInstructions.class index 7e1d54f..9443f1e 100644 Binary files a/out/production/Robot_Factory_PR/utility/interfaces/RobotInstructions.class and b/src/out/production/Robot_Factory_PR/utility/interfaces/RobotInstructions.class differ diff --git a/out/production/Robot_Factory_PR/utility/robot_exceptions/ArrayEmptyException.class b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/ArrayEmptyException.class similarity index 86% rename from out/production/Robot_Factory_PR/utility/robot_exceptions/ArrayEmptyException.class rename to src/out/production/Robot_Factory_PR/utility/robot_exceptions/ArrayEmptyException.class index 19a7b23..56d740e 100644 Binary files a/out/production/Robot_Factory_PR/utility/robot_exceptions/ArrayEmptyException.class and b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/ArrayEmptyException.class differ diff --git a/out/production/Robot_Factory_PR/utility/robot_exceptions/ExceptionStorage.class b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/ExceptionStorage.class similarity index 94% rename from out/production/Robot_Factory_PR/utility/robot_exceptions/ExceptionStorage.class rename to src/out/production/Robot_Factory_PR/utility/robot_exceptions/ExceptionStorage.class index 0775674..662da0e 100644 Binary files a/out/production/Robot_Factory_PR/utility/robot_exceptions/ExceptionStorage.class and b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/ExceptionStorage.class differ diff --git a/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotException.class b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotException.class similarity index 93% rename from out/production/Robot_Factory_PR/utility/robot_exceptions/RobotException.class rename to src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotException.class index b26ffd4..f22d7b3 100644 Binary files a/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotException.class and b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotException.class differ diff --git a/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotIllegalStateException.class b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotIllegalStateException.class similarity index 87% rename from out/production/Robot_Factory_PR/utility/robot_exceptions/RobotIllegalStateException.class rename to src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotIllegalStateException.class index a058331..d0643ab 100644 Binary files a/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotIllegalStateException.class and b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotIllegalStateException.class differ diff --git a/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotMagicValueException.class b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotMagicValueException.class similarity index 87% rename from out/production/Robot_Factory_PR/utility/robot_exceptions/RobotMagicValueException.class rename to src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotMagicValueException.class index 90d2da7..5a41dab 100644 Binary files a/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotMagicValueException.class and b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/RobotMagicValueException.class differ diff --git a/out/production/Robot_Factory_PR/utility/robot_exceptions/robotExceptions.class b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/robotExceptions.class similarity index 92% rename from out/production/Robot_Factory_PR/utility/robot_exceptions/robotExceptions.class rename to src/out/production/Robot_Factory_PR/utility/robot_exceptions/robotExceptions.class index d731254..a50f274 100644 Binary files a/out/production/Robot_Factory_PR/utility/robot_exceptions/robotExceptions.class and b/src/out/production/Robot_Factory_PR/utility/robot_exceptions/robotExceptions.class differ diff --git a/src/ui/UI.java b/src/ui/UI.java new file mode 100644 index 0000000..c42ab1e --- /dev/null +++ b/src/ui/UI.java @@ -0,0 +1,144 @@ +package src.ui; + +import src.domain.Robot; +import src.domain.RobotType; +import src.facade.FactorySystem; +import infrastructure.Persistenz; +import java.util.Scanner; + +public class UI { + + private FactorySystem fs; + private String name; + + Scanner sc = new Scanner(System.in); + public UI (FactorySystem fs){ + this.fs = fs; + hauptmenü(); + + } + public UI (String name){ + this.name = name; + if(Persistenz.existsSavedData(name)){ + try{ + this.fs = (FactorySystem) Persistenz.loadFactoryData(name); + }catch(Exception ignored){ + } + }else{ + this.fs = new FactorySystem(name); + } + } + /** + * starting screen + */ + private void hauptmenü() { + mainloop: + while(true){ + System.out.println(); + System.out.println("_______________________________"); + System.out.println("Sie haben folgende optionen: "); + System.out.println("-1- -- Alle Roboter anzeigen --"); + System.out.println("-2- -- Erzeuge neuen Roboter --"); + System.out.println("-3- ----- Roboter benutzen ----"); + System.out.println("-4- ---------- Exit -----------"); + System.out.print(" > "); + //User options + try{ + int input = Integer.parseInt(sc.nextLine()); + switch(input){ + case 1: + listAllRobots();break; + case 2: buildNewRobot();break; + case 3: useRobot();break; + case 4: break mainloop; + default: + System.out.println("Keine valide Option auswahl"); break; + } + }catch(NumberFormatException e){ + System.out.println("Kein valider Input"); + } + } + System.out.println("Auf Wiedersehen"); + } + /** + * display all existing robots + */ + private void listAllRobots(){ + String[] listOfAll = fs.getAllRobots(); + if(listOfAll.length > 0){ + System.out.println("Diese Roboter existieren bereits:"); + for (String s: listOfAll) { + System.out.println(s); + } + }else{ + System.out.println("Es wurden noch keine Roboter erzeugt"); + } + } + /** + * create a new robot + */ + private void buildNewRobot(){ + System.out.println("Wie soll der neue Roboter heißen"); + System.out.print(" > "); + String name = sc.nextLine(); + System.out.println("Welche Art Roboter wollen Sie"); + System.out.println(" [0] für R2D2 und [1] für C3PO"); + System.out.print(" > "); + //user enters which type of robot he wants + int in = Integer.parseInt(sc.nextLine()); + RobotType type = null; + if(in == 0) { + type = RobotType.R2D2; + } else if(in == 1) { + type = RobotType.C3PO; + } + if(fs.buildNewRobot(name, type)){ + switch (type) { + case R2D2 -> System.out.println("Neuer Roboter vom typ R2D2 mit dem Namen " + name + " wurde erzeugt"); + case C3PO -> System.out.println("Neuer Roboter vom typ C3PO mit dem Namen " + name + " wurde erzeugt"); + } + }else{ + System.out.println("Anlegen des Roboters fehlgeschlagen"); + } + } + /** + * let the robots sort + */ + private void useRobot(){ + System.out.println("Welchen Roboter wollen Sie verwenden"); + listAllRobots(); + System.out.print(" ID > "); + int idInput = Integer.parseInt(sc.nextLine()); + // Change the searchForRobot Methode (safety) + Robot r = fs.searchForRobot(idInput); + System.out.println("Du hast " + r.getName() + " gewählt der vom Typ " + r.getType() + " ist"); + mainloop: + while(true) { + System.out.println(); + System.out.println("_______________________________"); + System.out.println("Sie haben folgende optionen: "); + System.out.println("-1- --- An oder Ausschalten ---"); + System.out.println("-2- -- Sortieren einer Liste --"); + System.out.println("-3- ---------- Exit -----------"); + System.out.print(" > "); + //User options + try { + int input = Integer.parseInt(sc.nextLine()); + switch (input) { + case 1: + listAllRobots(); + break; + case 2: + buildNewRobot(); + break; + case 3: + break; + default: + System.out.println("Keine valide Option auswahl"); break; + } + }catch(NumberFormatException e) { + System.out.println("Kein valider Input"); + } + } + } +} diff --git a/utility/interfaces/Robot.java b/src/utility/interfaces/Robot.java similarity index 70% rename from utility/interfaces/Robot.java rename to src/utility/interfaces/Robot.java index 474b644..62bc4ff 100644 --- a/utility/interfaces/Robot.java +++ b/src/utility/interfaces/Robot.java @@ -1,5 +1,5 @@ /* (c) 2012 Thomas Smits */ -package utility.interfaces; +package src.utility.interfaces; /** @@ -10,6 +10,6 @@ package utility.interfaces; public interface Robot extends RobotControl, RobotInstructions{ - // keine eigenen Methoden + // Don't write methods here } \ No newline at end of file diff --git a/utility/interfaces/RobotControl.java b/src/utility/interfaces/RobotControl.java similarity index 97% rename from utility/interfaces/RobotControl.java rename to src/utility/interfaces/RobotControl.java index b204e0e..764eb01 100644 --- a/utility/interfaces/RobotControl.java +++ b/src/utility/interfaces/RobotControl.java @@ -1,5 +1,5 @@ -package utility.interfaces; -import utility.robot_exceptions.RobotException; +package src.utility.interfaces; +import src.utility.robot_exceptions.RobotException; /** * Das Interface repräsentiert einen einfachen Roboter mit seinen Funktionen. diff --git a/utility/interfaces/RobotInstructions.java b/src/utility/interfaces/RobotInstructions.java similarity index 90% rename from utility/interfaces/RobotInstructions.java rename to src/utility/interfaces/RobotInstructions.java index 8d4d3c4..5837ba3 100644 --- a/utility/interfaces/RobotInstructions.java +++ b/src/utility/interfaces/RobotInstructions.java @@ -1,8 +1,8 @@ -package utility.interfaces; +package src.utility.interfaces; -import utility.robot_exceptions.RobotException; -import utility.robot_exceptions.RobotIllegalStateException; -import utility.robot_exceptions.RobotMagicValueException; +import src.utility.robot_exceptions.RobotException; +import src.utility.robot_exceptions.RobotIllegalStateException; +import src.utility.robot_exceptions.RobotMagicValueException; /** diff --git a/utility/robot_exceptions/ArrayEmptyException.java b/src/utility/robot_exceptions/ArrayEmptyException.java similarity index 82% rename from utility/robot_exceptions/ArrayEmptyException.java rename to src/utility/robot_exceptions/ArrayEmptyException.java index 6ec8001..27263a9 100644 --- a/utility/robot_exceptions/ArrayEmptyException.java +++ b/src/utility/robot_exceptions/ArrayEmptyException.java @@ -1,4 +1,4 @@ -package utility.robot_exceptions; +package src.utility.robot_exceptions; public class ArrayEmptyException extends RobotException{ public ArrayEmptyException(robotExceptions type,String errorMessage){ diff --git a/utility/robot_exceptions/ExceptionStorage.java b/src/utility/robot_exceptions/ExceptionStorage.java similarity index 88% rename from utility/robot_exceptions/ExceptionStorage.java rename to src/utility/robot_exceptions/ExceptionStorage.java index 103c1b9..aee64b6 100644 --- a/utility/robot_exceptions/ExceptionStorage.java +++ b/src/utility/robot_exceptions/ExceptionStorage.java @@ -1,4 +1,4 @@ -package utility.robot_exceptions; +package src.utility.robot_exceptions; import java.io.Serializable; import java.time.LocalDateTime; @@ -14,7 +14,9 @@ public class ExceptionStorage implements Serializable { LocalDateTime now = LocalDateTime.now(); this.date = now; } - + /** + * @param message of the exception + */ public void saveLatestErrorMessage(RobotException message){ this.message = message; this.date = LocalDateTime.now(); @@ -23,5 +25,4 @@ public class ExceptionStorage implements Serializable { public RobotException getLastErrorMessage(){ return this.message; } - } diff --git a/utility/robot_exceptions/RobotException.java b/src/utility/robot_exceptions/RobotException.java similarity index 80% rename from utility/robot_exceptions/RobotException.java rename to src/utility/robot_exceptions/RobotException.java index 241289b..3f3cf29 100644 --- a/utility/robot_exceptions/RobotException.java +++ b/src/utility/robot_exceptions/RobotException.java @@ -1,4 +1,4 @@ -package utility.robot_exceptions; +package src.utility.robot_exceptions; public class RobotException extends Exception{ robotExceptions currentType; @@ -10,6 +10,11 @@ public class RobotException extends Exception{ } + /** + * @param types + * @param name + * @return a combined String of both + */ private static String getMessage(robotExceptions types, String name){ return name + " " + types.getMessage(); } diff --git a/utility/robot_exceptions/RobotIllegalStateException.java b/src/utility/robot_exceptions/RobotIllegalStateException.java similarity index 66% rename from utility/robot_exceptions/RobotIllegalStateException.java rename to src/utility/robot_exceptions/RobotIllegalStateException.java index 5dcd6b7..51316de 100644 --- a/utility/robot_exceptions/RobotIllegalStateException.java +++ b/src/utility/robot_exceptions/RobotIllegalStateException.java @@ -1,7 +1,11 @@ -package utility.robot_exceptions; +package src.utility.robot_exceptions; public class RobotIllegalStateException extends RobotException{ + /** + * @param type + * @param errormessage + */ public RobotIllegalStateException(robotExceptions type, String errormessage){ super(type, errormessage); } diff --git a/utility/robot_exceptions/RobotMagicValueException.java b/src/utility/robot_exceptions/RobotMagicValueException.java similarity index 65% rename from utility/robot_exceptions/RobotMagicValueException.java rename to src/utility/robot_exceptions/RobotMagicValueException.java index 2fb8d2b..6fc65fa 100644 --- a/utility/robot_exceptions/RobotMagicValueException.java +++ b/src/utility/robot_exceptions/RobotMagicValueException.java @@ -1,6 +1,10 @@ -package utility.robot_exceptions; +package src.utility.robot_exceptions; public class RobotMagicValueException extends RobotException { + /** + * @param type + * @param errormessage + */ public RobotMagicValueException(robotExceptions type, String errormessage) { super(type, errormessage); } diff --git a/utility/robot_exceptions/robotExceptions.java b/src/utility/robot_exceptions/robotExceptions.java similarity index 89% rename from utility/robot_exceptions/robotExceptions.java rename to src/utility/robot_exceptions/robotExceptions.java index 8ac8e3d..0ba3351 100644 --- a/utility/robot_exceptions/robotExceptions.java +++ b/src/utility/robot_exceptions/robotExceptions.java @@ -1,4 +1,4 @@ -package utility.robot_exceptions; +package src.utility.robot_exceptions; public enum robotExceptions { ILLEGALSTATE("ist in einem illegalen Zustand"), diff --git a/test_factoryFactory.ser b/test_factoryFactory.ser deleted file mode 100644 index 45cdbe0..0000000 Binary files a/test_factoryFactory.ser and /dev/null differ diff --git a/domain/C3POTest.java b/tests/tests/C3POTest.java similarity index 66% rename from domain/C3POTest.java rename to tests/tests/C3POTest.java index 7d323b5..ab2d158 100644 --- a/domain/C3POTest.java +++ b/tests/tests/C3POTest.java @@ -1,57 +1,57 @@ -package domain; +package tests.tests; +import src.domain.C3PO; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import utility.robot_exceptions.RobotException; +import src.utility.robot_exceptions.RobotException; +import src.utility.robot_exceptions.RobotMagicValueException; import static org.junit.jupiter.api.Assertions.*; class C3POTest { - C3PO Herbert; + C3PO herbert; int id = 0; String name = "Herbert"; @BeforeEach void setup(){ - Herbert = new C3PO(id, name); + herbert = new C3PO(id, name); } - //Tests for basic functions @Test void getId() { - - assertEquals(id, Herbert.getId()); + assertEquals(id, herbert.getId()); } @Test void getName() { - assertEquals(name, Herbert.getName()); + assertEquals(name, herbert.getName()); assertEquals(name, - Herbert.getName()); + herbert.getName()); } @Test void triggerPowerSwitch() { - Herbert.triggerPowerSwitch(); - assertTrue(Herbert.isPowerOn()); + herbert.triggerPowerSwitch(); + assertTrue(herbert.isPowerOn()); } @Test void isPowerOn() { - assertFalse(Herbert.isPowerOn()); - Herbert.triggerPowerSwitch(); - assertTrue(Herbert.isPowerOn()); + assertFalse(herbert.isPowerOn()); + herbert.triggerPowerSwitch(); + assertTrue(herbert.isPowerOn()); } @Test void speak(){ - Herbert.triggerPowerSwitch(); + herbert.triggerPowerSwitch(); String solution = "12; 2; 4; 5; 12; 2; 4; 7; 56; 433; 23"; int[] input = {12, 2, 4, 5, 12, 2, 4, 7, 56, 433, 23}; String array = ""; try{ - array = Herbert.speak(input); + array = herbert.speak(input); }catch(RobotException re){ System.out.println(re); } @@ -65,13 +65,13 @@ class C3POTest { int[] input = { 4, 5, 12, 2, 4, 7, 56, 433, 23}; int[] value = new int[9]; try{ - value = Herbert.think(input); + value = herbert.think(input); }catch(RobotException re){ System.out.println(re); } - Herbert.triggerPowerSwitch(); + herbert.triggerPowerSwitch(); try{ - value = Herbert.think(input); + value = herbert.think(input); }catch(RobotException re){ System.out.println(re); } @@ -81,19 +81,22 @@ class C3POTest { } } - + @Test + void thinkTestMagicNumberException() { + assertThrows(RobotMagicValueException.class, () -> herbert.think(new int[]{42})); + } @Test void magicValueException(){ int[] input = {3,2,42}; - Herbert.triggerPowerSwitch(); + herbert.triggerPowerSwitch(); String expectedMessage = "Herbert has an unknown error. Code 42."; try{ - int[] solution = Herbert.think(input); + int[] solution = herbert.think(input); }catch(RobotException re){ assertEquals(0, expectedMessage.compareTo(re.getMessage())); } try{ - String test = Herbert.speak(input); + String test = herbert.speak(input); }catch(RobotException re){ assertEquals(0, expectedMessage.compareTo(re.getMessage())); } @@ -104,12 +107,12 @@ class C3POTest { int[] input = {3,2,42}; String expectedMessage = "Herbert is turned off."; try{ - int[] solution = Herbert.think(input); + int[] solution = herbert.think(input); }catch(RobotException re){ assertEquals(0, expectedMessage.compareTo(re.getMessage())); } try{ - String test = Herbert.speak(input); + String test = herbert.speak(input); }catch(RobotException re){ assertEquals(0, expectedMessage.compareTo(re.getMessage())); } @@ -119,16 +122,16 @@ class C3POTest { @Test void arrayEmptyException(){ String expectedMessage = "Herbert got an empty array."; - Herbert.triggerPowerSwitch(); + herbert.triggerPowerSwitch(); try{ - int[] solution = Herbert.think(new int[0]); + int[] solution = herbert.think(new int[0]); }catch(RobotException re){ System.out.println(re); assertEquals(0, expectedMessage.compareTo(re.getMessage())); } try{ - String test = Herbert.speak(new int[0]); + String test = herbert.speak(new int[0]); }catch(RobotException re){ System.out.println(re); assertEquals(0, expectedMessage.compareTo(re.getMessage())); diff --git a/domain/R2D2Test.java b/tests/tests/R2D2Test.java similarity index 95% rename from domain/R2D2Test.java rename to tests/tests/R2D2Test.java index f84f794..31ec999 100644 --- a/domain/R2D2Test.java +++ b/tests/tests/R2D2Test.java @@ -1,5 +1,6 @@ -package domain; +package tests; +import src.domain.R2D2; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; import static org.junit.jupiter.api.Assertions.*; @@ -18,7 +19,6 @@ class R2D2Test { //Tests for basic functions @Test void getId() { - assertEquals(id, Herbert.getId()); } diff --git a/ui/UI.java b/ui/UI.java deleted file mode 100644 index 70080cb..0000000 --- a/ui/UI.java +++ /dev/null @@ -1,108 +0,0 @@ -package ui; - - - -import domain.Robot; -import facade.FactorySystem; -import infrastructure.Persistenz; -import java.util.Scanner; - -public class UI { - - private FactorySystem fs; - private String name; - - Scanner sc = new Scanner(System.in); - public UI (FactorySystem fs){ - this.fs = fs; - hauptmenü(); - - } - public UI (String name){ - this.name = name; - if(Persistenz.existsSavedData(name)){ - try{ - this.fs = (FactorySystem) Persistenz.loadFactoryData(name); - }catch(Exception ignored){ - } - }else{ - this.fs = new FactorySystem(name); - } - } - //starting screen - private void hauptmenü() { - mainloop: - while(true){ - System.out.println(); - System.out.println("____________________________"); - System.out.println("Sie haben folgende optionen:"); - System.out.println("-1- --- show all robots ----"); - System.out.println("-2- --- build new robot ----"); - System.out.println("-3- ------- use robot ------"); - System.out.println("-4- --------- Exit ---------"); - System.out.print(" > "); - //User options - try{ - int input = Integer.parseInt(sc.nextLine()); - switch(input){ - case 1: - listAllRobots();break; - case 2: buildNewRobot();break; - case 3: useRobot();break; - case 4: break mainloop; - default: - System.out.println("this is an invalid option"); break; - } - }catch(NumberFormatException e){ - System.out.println("invalid input"); - } - } - System.out.println("Good Bye"); - } - //display all existing robots - private void listAllRobots(){ - String[] listOfAll = fs.getAllRobots(); - if(listOfAll.length > 0){ - System.out.println("These robtos exist right now:"); - for (String s: listOfAll) { - System.out.println(s); - } - }else{ - System.out.println("There are no robots yet."); - } - } - //create a new robot - private void buildNewRobot(){ - System.out.println("What shall the name of the robot be?"); - System.out.print(" > "); - String name = sc.nextLine(); - System.out.println("Which type of robot do u want?"); - System.out.println(" [0] for R2D2 and [1] for C3PO"); - System.out.print(" > "); - //user enters which type of robot he wants - int type = Integer.parseInt(sc.nextLine()); - if(fs.buildNewRobot(name, type)){ - switch (type) { - case 0 -> System.out.println("Created new Robot of type R2D2 with the name " + name); - case 1 -> System.out.println("Created new Robot of type C3PO with the name " + name); - } - }else{ - System.out.println("Anlegen des Roboters fehlgeschlagen"); - } - } - //let the robots sort - private void useRobot(){ - System.out.println("Which robot do you want to use?"); - listAllRobots(); - System.out.print(" ID > "); - int input = Integer.parseInt(sc.nextLine()); - // Change the searchForRobot Methode (safety) - Robot r = fs.searchForRobot(input); - System.out.println("You choose " + r.getName() + " of type " + r.getType()); - System.out.println("Yout have following options"); - mainloop: - while(true){ - - } - } -}