refactoring
parent
addbf64bdd
commit
aa77b2fcc6
|
@ -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.
|
|
@ -0,0 +1,4 @@
|
||||||
|
package de.hsmannheim.informatik.name.domain;
|
||||||
|
|
||||||
|
public class RobotFactory {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package de.hsmannheim.informatik.name.domain;
|
||||||
|
|
||||||
|
public enum RobotType {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package de.hsmannheim.informatik.name.domain.exceptions;
|
||||||
|
|
||||||
|
public class RobotException extends Exception {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package de.hsmannheim.informatik.name.domain.exceptions;
|
||||||
|
|
||||||
|
public class RobotIllegalStateException extends Exception {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package de.hsmannheim.informatik.name.domain.exceptions;
|
||||||
|
|
||||||
|
public class RobotMagicValueException extends Exception {
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/* (c) 2012 Thomas Smits */
|
/* (c) 2012 Thomas Smits */
|
||||||
package tpe.exceptions.roboter;
|
package de.hsmannheim.informatik.name.domain.robot_interfaces;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface für Roboter.
|
* Interface für Roboter.
|
|
@ -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.
|
* 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
|
* unveränderlich. Man kann einen Roboter jederzeit über die
|
||||||
* <code>getName()</code>-Methode nach seinem Namen fragen.
|
* <code>getName()</code>-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
|
* Seriennummer. Diese wird bei der Produktion festgelegt und hat einen vom
|
||||||
* Roboter-Typ abhängigen Bereich möglicher Werte. Innerhalb des Bereiches wird
|
* Roboter-Typ abhängigen Bereich möglicher Werte. Innerhalb des Bereiches wird
|
||||||
* die Seriennummer zufällig vergeben. Die Seriennummer kann auch bei
|
* die Seriennummer zufällig vergeben. Die Seriennummer kann auch bei
|
|
@ -1,8 +1,8 @@
|
||||||
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;
|
||||||
import tpe.exceptions.roboter.exceptions.RobotIllegalStateException;
|
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
|
||||||
import tpe.exceptions.roboter.exceptions.RobotMagicValueException;
|
import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Das Interface repräsentiert den Befehlssatz eines einfachen Roboters.
|
* Das Interface repräsentiert den Befehlssatz eines einfachen Roboters.
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +0,0 @@
|
||||||
package tpe.exceptions.roboter.exceptions;
|
|
||||||
|
|
||||||
public class RobotException extends Throwable {
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
package tpe.exceptions.roboter.exceptions;
|
|
||||||
|
|
||||||
public class RobotIllegalStateException extends Throwable {
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
package tpe.exceptions.roboter.exceptions;
|
|
||||||
|
|
||||||
public class RobotMagicValueException extends Throwable {
|
|
||||||
}
|
|
|
@ -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() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue