diff --git a/out/production/Robot_Factory_PR/.idea/misc.xml b/out/production/Robot_Factory_PR/.idea/misc.xml
index d15472f..b789a5e 100644
--- a/out/production/Robot_Factory_PR/.idea/misc.xml
+++ b/out/production/Robot_Factory_PR/.idea/misc.xml
@@ -1,6 +1,6 @@
-
-
+
+
\ 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 bea4650..c170efe 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
deleted file mode 100644
index d7c298d..0000000
Binary files a/out/production/Robot_Factory_PR/domain/C3PO.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 b2de0b8..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/Robot.class b/out/production/Robot_Factory_PR/domain/Robot.class
deleted file mode 100644
index ea0b3c0..0000000
Binary files a/out/production/Robot_Factory_PR/domain/Robot.class and /dev/null differ
diff --git a/out/production/Robot_Factory_PR/facade/FactorySystem.class b/out/production/Robot_Factory_PR/facade/FactorySystem.class
deleted file mode 100644
index df80877..0000000
Binary files a/out/production/Robot_Factory_PR/facade/FactorySystem.class and /dev/null differ
diff --git a/out/production/Robot_Factory_PR/test_factoryFactory.ser b/out/production/Robot_Factory_PR/test_factoryFactory.ser
index 45cdbe0..05a9170 100644
Binary files a/out/production/Robot_Factory_PR/test_factoryFactory.ser and b/out/production/Robot_Factory_PR/test_factoryFactory.ser 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 50def97..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 86%
rename from domain/C3PO.java
rename to src/domain/C3PO.java
index 75c40f1..615371f 100644
--- a/domain/C3PO.java
+++ b/src/domain/C3PO.java
@@ -6,10 +6,14 @@ import utility.robot_exceptions.robotExceptions;
public class C3PO extends Robot {
public C3PO(int id, String name){
- super(id, name, "C3PO");
+ 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 68%
rename from domain/Factory.java
rename to src/domain/Factory.java
index 18d9b9f..3b02a16 100644
--- a/domain/Factory.java
+++ b/src/domain/Factory.java
@@ -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 69%
rename from domain/Nexus6.java
rename to src/domain/Nexus6.java
index bb4f6bc..0cf2ea2 100644
--- a/domain/Nexus6.java
+++ b/src/domain/Nexus6.java
@@ -1,5 +1,4 @@
package domain;
-
import utility.robot_exceptions.ExceptionStorage;
import utility.robot_exceptions.RobotException;
import utility.robot_exceptions.robotExceptions;
@@ -9,21 +8,28 @@ 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 92%
rename from domain/R2D2.java
rename to src/domain/R2D2.java
index 1c67c46..5b208d6 100644
--- a/domain/R2D2.java
+++ b/src/domain/R2D2.java
@@ -1,6 +1,6 @@
package domain;
-
+import utility.interfaces.RobotInstructions;
import utility.robot_exceptions.ExceptionStorage;
import utility.robot_exceptions.RobotException;
import utility.robot_exceptions.robotExceptions;
@@ -11,11 +11,11 @@ public class R2D2 extends Robot {
* @param name> String
*/
public R2D2(int id, String name){
- super(id, name, "R2D2");
+ super(id, name, RobotType.R2D2);
}
/**
- * @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 79%
rename from domain/Robot.java
rename to src/domain/Robot.java
index e8dbddd..3851d4c 100644
--- a/domain/Robot.java
+++ b/src/domain/Robot.java
@@ -1,5 +1,5 @@
package domain;
-
+import utility.interfaces.RobotControl;
import utility.robot_exceptions.ExceptionStorage;
import utility.robot_exceptions.RobotException;
import utility.robot_exceptions.robotExceptions;
@@ -10,18 +10,15 @@ 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;
- }
+
protected ExceptionStorage exceptions;
private int id;
private final String name;
private boolean power;
- private String type;
+ private RobotType type;
- public Robot(int id, String name, String type){
+ public Robot(int id, String name, RobotType type){
this.id = id;
this.name = name;
this.power = false;
@@ -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(){
+
+ 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..9ace46a
--- /dev/null
+++ b/src/domain/RobotType.java
@@ -0,0 +1,13 @@
+package 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 86%
rename from facade/FactorySystem.java
rename to src/facade/FactorySystem.java
index ca00e4a..7cfefcb 100644
--- a/facade/FactorySystem.java
+++ b/src/facade/FactorySystem.java
@@ -2,6 +2,7 @@ package facade;
import domain.Factory;
import domain.Robot;
+import domain.RobotType;
import infrastructure.Persistenz;
public class FactorySystem {
@@ -25,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 {
@@ -41,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/src/out/production/Robot_Factory_PR/domain/C3PO.class b/src/out/production/Robot_Factory_PR/domain/C3PO.class
new file mode 100644
index 0000000..4e45319
Binary files /dev/null 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 57%
rename from out/production/Robot_Factory_PR/domain/R2D2.class
rename to src/out/production/Robot_Factory_PR/domain/R2D2.class
index 54b8f8b..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/src/out/production/Robot_Factory_PR/facade/FactorySystem.class b/src/out/production/Robot_Factory_PR/facade/FactorySystem.class
new file mode 100644
index 0000000..f510c18
Binary files /dev/null and b/src/out/production/Robot_Factory_PR/facade/FactorySystem.class differ
diff --git a/out/production/Robot_Factory_PR/infrastructure/Persistenz.class b/src/out/production/Robot_Factory_PR/infrastructure/Persistenz.class
similarity index 98%
rename from out/production/Robot_Factory_PR/infrastructure/Persistenz.class
rename to src/out/production/Robot_Factory_PR/infrastructure/Persistenz.class
index 9c31bf5..92e6b24 100644
Binary files a/out/production/Robot_Factory_PR/infrastructure/Persistenz.class 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 98%
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 fdcc11e..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..544f3bc
--- /dev/null
+++ b/src/ui/UI.java
@@ -0,0 +1,144 @@
+package ui;
+
+import domain.Robot;
+import domain.RobotType;
+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- -- 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 85%
rename from utility/interfaces/Robot.java
rename to src/utility/interfaces/Robot.java
index 474b644..c4886c3 100644
--- a/utility/interfaces/Robot.java
+++ b/src/utility/interfaces/Robot.java
@@ -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 100%
rename from utility/interfaces/RobotControl.java
rename to src/utility/interfaces/RobotControl.java
diff --git a/utility/interfaces/RobotInstructions.java b/src/utility/interfaces/RobotInstructions.java
similarity index 100%
rename from utility/interfaces/RobotInstructions.java
rename to src/utility/interfaces/RobotInstructions.java
diff --git a/utility/robot_exceptions/ArrayEmptyException.java b/src/utility/robot_exceptions/ArrayEmptyException.java
similarity index 100%
rename from utility/robot_exceptions/ArrayEmptyException.java
rename to src/utility/robot_exceptions/ArrayEmptyException.java
diff --git a/utility/robot_exceptions/ExceptionStorage.java b/src/utility/robot_exceptions/ExceptionStorage.java
similarity index 77%
rename from utility/robot_exceptions/ExceptionStorage.java
rename to src/utility/robot_exceptions/ExceptionStorage.java
index 289976c..31068bc 100644
--- a/utility/robot_exceptions/ExceptionStorage.java
+++ b/src/utility/robot_exceptions/ExceptionStorage.java
@@ -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,14 +25,4 @@ public class ExceptionStorage implements Serializable {
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/utility/robot_exceptions/RobotException.java b/src/utility/robot_exceptions/RobotException.java
similarity index 85%
rename from utility/robot_exceptions/RobotException.java
rename to src/utility/robot_exceptions/RobotException.java
index e8d1485..20c5e96 100644
--- a/utility/robot_exceptions/RobotException.java
+++ b/src/utility/robot_exceptions/RobotException.java
@@ -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 79%
rename from utility/robot_exceptions/RobotIllegalStateException.java
rename to src/utility/robot_exceptions/RobotIllegalStateException.java
index 5dcd6b7..6f4705a 100644
--- a/utility/robot_exceptions/RobotIllegalStateException.java
+++ b/src/utility/robot_exceptions/RobotIllegalStateException.java
@@ -2,6 +2,10 @@ package 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 78%
rename from utility/robot_exceptions/RobotMagicValueException.java
rename to src/utility/robot_exceptions/RobotMagicValueException.java
index 2fb8d2b..d70623f 100644
--- a/utility/robot_exceptions/RobotMagicValueException.java
+++ b/src/utility/robot_exceptions/RobotMagicValueException.java
@@ -1,6 +1,10 @@
package 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 100%
rename from utility/robot_exceptions/robotExceptions.java
rename to src/utility/robot_exceptions/robotExceptions.java
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..bd4ffa8 100644
--- a/domain/C3POTest.java
+++ b/tests/tests/C3POTest.java
@@ -1,57 +1,57 @@
-package domain;
+package 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 bada1c3..0000000
--- a/ui/UI.java
+++ /dev/null
@@ -1,106 +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){
-
- }
- }
-}