Sorting algorthyms

main
Cedric Hermann 2022-12-14 09:48:20 +01:00
parent d4362b1cf4
commit 15d35036b2
35 changed files with 317 additions and 114 deletions

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_17" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library"> <orderEntry type="module-library">
<library name="JUnit5.8.1"> <library name="JUnit5.8.1">
@ -23,5 +23,31 @@
<SOURCES /> <SOURCES />
</library> </library>
</orderEntry> </orderEntry>
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component> </component>
</module> </module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="17" />
</component>
</project>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -1,11 +1,15 @@
import domain.C3PO; import domain.C3PO;
import domain.R2D2;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
C3PO Herbert = new C3PO(0, "Herbert");
int[] input = {6,5,4,3,2,1}; int[] input = {6,5,4,3,2,1};
C3PO c = new C3PO(1000, "cc");
System.out.println(c.sorting(input));
R2D2 r = new R2D2(1000, "cc");
System.out.println(r.sorting(input));
//just some testing //just some testing
/*C3PO Herbert = new C3PO(0, "Herbert"); /*C3PO Herbert = new C3PO(0, "Herbert");

View File

@ -1,10 +1,34 @@
package domain; package domain;
public class C3PO extends RobotBasics { import org.junit.jupiter.params.shadow.com.univocity.parsers.common.fields.ColumnMapping;
import robot.interfaces.Sorting;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicReference;
public class C3PO extends RobotBasics implements Sorting {
public C3PO(int id, String name){ public C3PO(int id, String name){
super(id, name); super(id, name);
} }
//@Override
public String sorting(int[] arr) {
//Insertionsort
for(int i=1;i<arr.length;i++){
int b = i-1;
int key = arr[i];
while(b>=0 && arr[b]>key) arr[b+1] = arr[b--];
arr[b+1] = key;
}
//Writing all values of the array into a String
String result = "" + arr[0];
if(arr.length > 1) {
for (int i = 1; i < arr.length; i++) {
result += ";" + arr[i];
}
}
return result;
}
} }

View File

@ -16,6 +16,7 @@ class C3POTest {
//Tests for basic functions //Tests for basic functions
/**
@Test @Test
void getId() { void getId() {
@ -42,6 +43,6 @@ class C3POTest {
assertTrue(Herbert.isPowerOn()); assertTrue(Herbert.isPowerOn());
} }
**/
} }

View File

@ -1,5 +1,9 @@
package domain; package domain;
import robot.interfaces.Sorting;
import java.util.Arrays;
public class R2D2 extends RobotBasics { public class R2D2 extends RobotBasics {
/** /**
* Constructor * Constructor
@ -8,7 +12,35 @@ public class R2D2 extends RobotBasics {
*/ */
public R2D2(int id, String name){ public R2D2(int id, String name){
super(id, name); super(id, name);
}
public String sorting(int[] arr) {
//Selectionsort
int small;
for (int i = 0; i <arr.length - 1; i++) {
small = i;
for (int j = i + 1; j < arr.length; j++) {
//if there is a smaller number on this position
if (arr[j] < arr[small]) {
small = j;
//swap values
int temp = arr[i];
arr[i] = arr[small];
arr[small] = temp;
}
}
}
//Writing all values of the array into a String
String result = "";
if(arr.length != 0) {
result = "" + arr[0];
if (arr.length > 1) {
for (int i = 1; i < arr.length; i++) {
result += "," + arr[i];
}
}
}
return result;
} }
} }

View File

@ -1,4 +0,0 @@
package facade;
public class Factory {
}

View File

@ -0,0 +1,10 @@
package facade;
public class RobotFactory {
enum RobotType {
C3PO, R2D2
}
}

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_17" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library"> <orderEntry type="module-library">
<library name="JUnit5.8.1"> <library name="JUnit5.8.1">
@ -23,5 +23,31 @@
<SOURCES /> <SOURCES />
</library> </library>
</orderEntry> </orderEntry>
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component> </component>
</module> </module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="17" />
</component>
</project>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -17,176 +17,248 @@
# Overview # Overview
## Packages ## Packages
* [Domain](#domain) * ### [Domain](#domain-1)
* [R2D2](#-klasse-r2d2-) * [R2D2](#-classe-r2d2-)
* [R2D2Test](#-testklasse-r2d2test-) * [R2D2Test](#-testclasse-r2d2test-)
* [C3P0](#-klasse-c3po-) * [C3P0](#-classe-c3po-)
* [Robot](#-interface-robot-) * [C3POTest](#-testclasse-c3potest-)
* [RobotControl](#-interface-robotcontrol-) * [RobotBasics](#-class-robotbasics-)
* [RobotControl](#-interface-robotinstructions-) * ### [Facade](#facade-1)
* [Facade](#facade) * [Factrory](#-classe-factory-)
* [Factrory](#-klasse-factory-) * ### [Infrastructure](#infratructure-1)
* [Infrastructure](#infratructure) * [Persistenz](#-classe-persistenz-)
* [Persistenz](#-klasse-persistenz-) * ### [robot](#robot-1)
* [UI](#ui) * ### [exceptions](#exceptions-1)
* [RobotException](#-class-robotexception-)
* [RobotIllegalStateException](#-class-robotillegalstateexception-)
* [RobotMagicValueException](#-class-robotmagicvalueexception-)
* ### [interfaces](#interfaces-1)
* [Robot](#-interface-robot-)
* [RobotControl](#-interface-robotcontroll-)
* [RobotInstructions](#-interface-robotinstructions-)
* [Sorting] vorläufig
* ### [UI](#ui-1)
* [UI](#-class-ui-)
## Sidefiles ## Sidefiles
* [Main](#-klasse-main-) * [Main](#-classe-main-)
* [makefile](#-makefile-for-Git-updates-) * [makefile](#-makefile-for-Git-updates-)
## Domain ## Domain
<h2 align="center"> Klasse R2D2 </h2> <h2 align="center"> Class R2D2 </h2>
### Variables: ### Variables:
``` `--not set yet--`
private int id
private String name
private boolean power
```
___ ___
### Methods: ### Methods:
``` `public R2D2():R2D2`
public R2D2():R2D2
//implemented from interface Robotcontrol
public getId():int
public getName():String
public triggerPowerSWitch():void
public isPowerOn():boolean
```
<h2 align="center"> TestKlasse R2D2Test </h2> <h2 align="center">
TestClass R2D2Test
</h2>
### Variables: ### Variables:
```
public int id `public int id`
public String name
public R2D2 Herbert `public String name`
```
___ `public R2D2 Herbert`
___
### Methods: ### Methods:
```
@BeforeEach
setup():void
@Test `@BeforeEach`
getId():void `setup():void`
getName():void
triggerPowerSwitch():void
iPowerOn():void
``` `@Test`
<h2 align="center"> Klasse C3PO </h2> `getId():void`
`getName():void`
`triggerPowerSwitch():void`
`iPowerOn():void`
<h2 align="center">
Class C3PO
</h2>
### Variables: ### Variables:
``` `--not set yet--`
--not set yet--
```
___ ___
### Methods: ### Methods:
``` `//construtor`
--not set yet--
```
<h2 align="center"> Interface Robot </h2> `public C3PO(): C3PO`
<h2 align="center">
TestClass C3PO
</h2>
### Variables:
`public int id`
`public String name`
`public C3PO Herbert`
___
### Methods: ### Methods:
``` `@BeforeEach`
--not set yet-- `setup():void`
```
`@Test`
`getId():void`
`getName():void`
`triggerPowerSwitch():void`
`iPowerOn():void`
<h2 align="center"> Interface RobotControl </h2>
<h2 align="center">
Class RobotBasics
</h2>
### Variables:
`private int id`
`private String name`
`private boolean power`
___
### Methods: ### Methods:
``` `public RobotBasics():RobotBasics`
--not set yet--
``` `public getId():int`
<h2 align="center"> Interface RobotInstructions </h2> `public getName():String`
### Methods: `public triggerPowerSwitch():void`
```
--not set yet--
```
`public ìsPowerOn():boolean`
`public speak():String`
`public think():int[]`
## facade ## facade
<h2 align="center"> Klasse Factory </h2> <h2 align="center"> Class Factory </h2>
### Variables: ### Variables:
``` `--not set yet--`
--not set yet--
```
___ ___
### Methods: ### Methods:
``` `--not set yet--`
--not set yet--
```
## Infrastructure ## Infrastructure
<h2 align="center"> Klasse Persistenz </h2> <h2 align="center"> Class Persistenz </h2>
### Variables: ### Variables:
``` `--not set yet--`
--not set yet--
```
___ ___
### Methods: ### Methods:
``` `--not set yet--`
--not set yet--
``` ## robot
### exceptions
<h2 align="center">
Class RobotException
</h2>
#### Methods:
`public RobotException():Exception`
<h2 align="center"> Class RobotIllegalStateException </h2>
#### Methods:
`public RobotIllegalStateException():RobotException`
<h2 align="center"> Class RobotMagicValueException </h2>
#### Methods:
`public RobotMagicValueException():RobotException`
### interfaces
<h2 align="center">
Interface Robot </h2>
#### Methods:
`--not set yet--`
<h2 align="center">
Interface RobotControl
</h2>
### Methods:
`--not set yet--`
<h2 align="center">
Interface RobotInstructions </h2>
### Methods:
`--not set yet--`
## UI ## UI
<h2 align="center"> Klasse UI </h2> <h2 align="center"> Class UI </h2>
### Variables: ### Variables:
``` `--not set yet--`
--not set yet--
```
___ ___
### Methods: ### Methods:
``` `--not set yet--`
--not set yet--
```
<h2 align="center"> Klasse Main </h2>
<h2 align="center"> Class Main </h2>
### Variables: ### Variables:
``` `--not set yet--`
--not set yet--
```
___ ___
### Methods: ### Methods:
``` `--not set yet--`
--not set yet--
```
<h2 align="center"> makefile for Git updates </h2> <h2 align="center"> makefile for Git updates </h2>
### Variables: ### Variables:
``` `--not set yet--`
--not set yet--
```
___ ___
### Methods: ### Methods:
```
update_readme: `update_readme:`
update_make:
update_all: `update_make:`
```
`update_all:`
## Aufgabe ## Aufgabe