From aa77b2fcc6da9726144a33802fb4e6a14710197a Mon Sep 17 00:00:00 2001 From: zlohbierdcul <82916072+zlohbierdcul@users.noreply.github.com> Date: Tue, 20 Dec 2022 12:58:23 +0100 Subject: [PATCH] refactoring --- README.md | 6 +++ .../informatik/name/domain/RobotFactory.java | 4 ++ .../informatik/name/domain/RobotType.java | 4 ++ .../domain/exceptions/RobotException.java | 4 ++ .../RobotIllegalStateException.java | 4 ++ .../exceptions/RobotMagicValueException.java | 4 ++ .../name/domain/robot_interfaces}/Robot.java | 2 +- .../robot_interfaces}/RobotControl.java | 6 +-- .../robot_interfaces}/RobotInstructions.java | 8 +-- .../informatik/name/domain/starwars/C3PO.java | 23 ++++++++ .../informatik/name/domain/starwars/R2D2.java | 28 ++++++++++ .../name/domain/starwars/StarWarsRobot.java | 53 +++++++++++++++++++ .../roboter/exceptions/RobotException.java | 4 -- .../RobotIllegalStateException.java | 4 -- .../exceptions/RobotMagicValueException.java | 4 -- tests/R2D2Test.java | 12 +++++ 16 files changed, 150 insertions(+), 20 deletions(-) create mode 100644 README.md create mode 100644 src/de/hsmannheim/informatik/name/domain/RobotFactory.java create mode 100644 src/de/hsmannheim/informatik/name/domain/RobotType.java create mode 100644 src/de/hsmannheim/informatik/name/domain/exceptions/RobotException.java create mode 100644 src/de/hsmannheim/informatik/name/domain/exceptions/RobotIllegalStateException.java create mode 100644 src/de/hsmannheim/informatik/name/domain/exceptions/RobotMagicValueException.java rename src/{tpe/exceptions/roboter => de/hsmannheim/informatik/name/domain/robot_interfaces}/Robot.java (74%) rename src/{tpe/exceptions/roboter => de/hsmannheim/informatik/name/domain/robot_interfaces}/RobotControl.java (92%) rename src/{tpe/exceptions/roboter => de/hsmannheim/informatik/name/domain/robot_interfaces}/RobotInstructions.java (86%) create mode 100644 src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java create mode 100644 src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java create mode 100644 src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java delete mode 100644 src/tpe/exceptions/roboter/exceptions/RobotException.java delete mode 100644 src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java delete mode 100644 src/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java create mode 100644 tests/R2D2Test.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..f829faf --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# RobotFactory + +## Style Guide +* For every method you write you also write the JUnit test and comments. + * [reference](https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html) +* Always mark the task you're currently working on on the kanban board and move it to the right phase. \ No newline at end of file diff --git a/src/de/hsmannheim/informatik/name/domain/RobotFactory.java b/src/de/hsmannheim/informatik/name/domain/RobotFactory.java new file mode 100644 index 0000000..a4efcf5 --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/RobotFactory.java @@ -0,0 +1,4 @@ +package de.hsmannheim.informatik.name.domain; + +public class RobotFactory { +} diff --git a/src/de/hsmannheim/informatik/name/domain/RobotType.java b/src/de/hsmannheim/informatik/name/domain/RobotType.java new file mode 100644 index 0000000..6ea83cd --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/RobotType.java @@ -0,0 +1,4 @@ +package de.hsmannheim.informatik.name.domain; + +public enum RobotType { +} diff --git a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotException.java b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotException.java new file mode 100644 index 0000000..e270194 --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotException.java @@ -0,0 +1,4 @@ +package de.hsmannheim.informatik.name.domain.exceptions; + +public class RobotException extends Exception { +} diff --git a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotIllegalStateException.java b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotIllegalStateException.java new file mode 100644 index 0000000..4f85eec --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotIllegalStateException.java @@ -0,0 +1,4 @@ +package de.hsmannheim.informatik.name.domain.exceptions; + +public class RobotIllegalStateException extends Exception { +} diff --git a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotMagicValueException.java b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotMagicValueException.java new file mode 100644 index 0000000..21d809d --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotMagicValueException.java @@ -0,0 +1,4 @@ +package de.hsmannheim.informatik.name.domain.exceptions; + +public class RobotMagicValueException extends Exception { +} diff --git a/src/tpe/exceptions/roboter/Robot.java b/src/de/hsmannheim/informatik/name/domain/robot_interfaces/Robot.java similarity index 74% rename from src/tpe/exceptions/roboter/Robot.java rename to src/de/hsmannheim/informatik/name/domain/robot_interfaces/Robot.java index 5358b2b..95827d5 100644 --- a/src/tpe/exceptions/roboter/Robot.java +++ b/src/de/hsmannheim/informatik/name/domain/robot_interfaces/Robot.java @@ -1,5 +1,5 @@ /* (c) 2012 Thomas Smits */ -package tpe.exceptions.roboter; +package de.hsmannheim.informatik.name.domain.robot_interfaces; /** * Interface für Roboter. diff --git a/src/tpe/exceptions/roboter/RobotControl.java b/src/de/hsmannheim/informatik/name/domain/robot_interfaces/RobotControl.java similarity index 92% rename from src/tpe/exceptions/roboter/RobotControl.java rename to src/de/hsmannheim/informatik/name/domain/robot_interfaces/RobotControl.java index ae70012..cfd6b36 100644 --- a/src/tpe/exceptions/roboter/RobotControl.java +++ b/src/de/hsmannheim/informatik/name/domain/robot_interfaces/RobotControl.java @@ -1,6 +1,6 @@ -package tpe.exceptions.roboter; +package de.hsmannheim.informatik.name.domain.robot_interfaces; -import tpe.exceptions.roboter.exceptions.RobotException; +import de.hsmannheim.informatik.name.domain.exceptions.RobotException; /** * Das Interface repräsentiert einen einfachen Roboter mit seinen Funktionen. @@ -10,7 +10,7 @@ import tpe.exceptions.roboter.exceptions.RobotException; * unveränderlich. Man kann einen Roboter jederzeit über die * getName()-Methode nach seinem Namen fragen. * - * Zusätzlich zum frei gewählten Namen, hat jeder Roboter noch eine + * Zusätzlich zum frei gewählten Namen hat jeder Roboter noch eine * Seriennummer. Diese wird bei der Produktion festgelegt und hat einen vom * Roboter-Typ abhängigen Bereich möglicher Werte. Innerhalb des Bereiches wird * die Seriennummer zufällig vergeben. Die Seriennummer kann auch bei diff --git a/src/tpe/exceptions/roboter/RobotInstructions.java b/src/de/hsmannheim/informatik/name/domain/robot_interfaces/RobotInstructions.java similarity index 86% rename from src/tpe/exceptions/roboter/RobotInstructions.java rename to src/de/hsmannheim/informatik/name/domain/robot_interfaces/RobotInstructions.java index 9426eb9..38a3529 100644 --- a/src/tpe/exceptions/roboter/RobotInstructions.java +++ b/src/de/hsmannheim/informatik/name/domain/robot_interfaces/RobotInstructions.java @@ -1,8 +1,8 @@ -package tpe.exceptions.roboter; +package de.hsmannheim.informatik.name.domain.robot_interfaces; -import tpe.exceptions.roboter.exceptions.RobotException; -import tpe.exceptions.roboter.exceptions.RobotIllegalStateException; -import tpe.exceptions.roboter.exceptions.RobotMagicValueException; +import de.hsmannheim.informatik.name.domain.exceptions.RobotException; +import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException; +import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException; /** * Das Interface repräsentiert den Befehlssatz eines einfachen Roboters. diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java b/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java new file mode 100644 index 0000000..3e31b53 --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java @@ -0,0 +1,23 @@ +package de.hsmannheim.informatik.name.domain.starwars; + +import de.hsmannheim.informatik.name.domain.exceptions.RobotException; + +public class C3PO extends StarWarsRobot { + @Override + public String speak(int[] zahlen) throws RobotException { + return null; + } + + @Override + public int[] think(int[] zahlen) throws RobotException { + int[] arrToSort = zahlen.clone(); + for (int i = 1; i < arrToSort.length; i++) { + for (int j = i; j > 0; j--) { + if (arrToSort[j-1] > arrToSort[j]) { + swap(arrToSort, j, j-1); + } + } + } + return arrToSort; + } +} diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java b/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java new file mode 100644 index 0000000..bc12cc4 --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java @@ -0,0 +1,28 @@ +package de.hsmannheim.informatik.name.domain.starwars; + +import de.hsmannheim.informatik.name.domain.exceptions.RobotException; + +public class R2D2 extends StarWarsRobot { + @Override + public String speak(int[] zahlen) throws RobotException { + return null; + } + + @Override + public int[] think(int[] zahlen) throws RobotException { + int[] arrayToSort = zahlen.clone(); + for (int i = 0; i < arrayToSort.length; i++) { + int smallest = Integer.MAX_VALUE; + int smallestIndex = 0; + for (int j = i; j < arrayToSort.length; j++) { + if (arrayToSort[j] < smallest) { + smallest = arrayToSort[j]; + smallestIndex = j; + } + } + swap(arrayToSort, smallestIndex, i); + } + reverse(arrayToSort); + return arrayToSort; + } +} diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java b/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java new file mode 100644 index 0000000..959ba2f --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java @@ -0,0 +1,53 @@ +package de.hsmannheim.informatik.name.domain.starwars; + +import de.hsmannheim.informatik.name.domain.robot_interfaces.Robot; +import de.hsmannheim.informatik.name.domain.exceptions.RobotException; + + +public abstract class StarWarsRobot implements Robot { + + @Override + public int getId() { + return 0; + } + + @Override + public String getName() { + return null; + } + + @Override + public void triggerPowerSwitch() { + + } + + @Override + public boolean isPowerOn() { + return false; + } + + @Override + public RobotException getLastException() { + return null; + } + + @Override + public abstract String speak(int[] zahlen) throws RobotException; + + @Override + public abstract int[] think(int[] zahlen) throws RobotException; + + protected static void swap(int[] arr, int a, int b) { + int temp = arr[a]; + arr[a] = arr[b]; + arr[b] = temp; + } + + protected static void reverse(int[] array) { + for (int i = 0; i < array.length / 2; i++) { + int temp = array[i]; + array[i] = array[array.length - i - 1]; + array[array.length - i - 1] = temp; + } + } +} diff --git a/src/tpe/exceptions/roboter/exceptions/RobotException.java b/src/tpe/exceptions/roboter/exceptions/RobotException.java deleted file mode 100644 index b2f26b0..0000000 --- a/src/tpe/exceptions/roboter/exceptions/RobotException.java +++ /dev/null @@ -1,4 +0,0 @@ -package tpe.exceptions.roboter.exceptions; - -public class RobotException extends Throwable { -} diff --git a/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java b/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java deleted file mode 100644 index 8c58beb..0000000 --- a/src/tpe/exceptions/roboter/exceptions/RobotIllegalStateException.java +++ /dev/null @@ -1,4 +0,0 @@ -package tpe.exceptions.roboter.exceptions; - -public class RobotIllegalStateException extends Throwable { -} diff --git a/src/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java b/src/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java deleted file mode 100644 index 5f68000..0000000 --- a/src/tpe/exceptions/roboter/exceptions/RobotMagicValueException.java +++ /dev/null @@ -1,4 +0,0 @@ -package tpe.exceptions.roboter.exceptions; - -public class RobotMagicValueException extends Throwable { -} diff --git a/tests/R2D2Test.java b/tests/R2D2Test.java new file mode 100644 index 0000000..fa6e7ba --- /dev/null +++ b/tests/R2D2Test.java @@ -0,0 +1,12 @@ +import static org.junit.jupiter.api.Assertions.*; + +class R2D2Test { + + @org.junit.jupiter.api.Test + void speak() { + } + + @org.junit.jupiter.api.Test + void think() { + } +} \ No newline at end of file