mirror of
https://github.com/Noratrieb/buchSort.git
synced 2026-01-14 08:55:03 +01:00
Initial commit
This commit is contained in:
commit
4618ca2123
11 changed files with 200 additions and 0 deletions
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
# Eclipse m2e generated files
|
||||
# Eclipse Core
|
||||
.project
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="buchSort" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/discord.xml
generated
Normal file
7
.idea/discord.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
||||
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/runConfigurations.xml
generated
Normal file
10
.idea/runConfigurations.xml
generated
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
25
pom.xml
Normal file
25
pom.xml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>buchSort</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
35
src/main/java/Buch.java
Normal file
35
src/main/java/Buch.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
public class Buch {
|
||||
private String buchID;
|
||||
private String autor;
|
||||
private String titel;
|
||||
private int erscheinungsjahr;
|
||||
private String genre;
|
||||
|
||||
public Buch(String buchID, String autor, String titel, int erscheinungsjahr, String genre) {
|
||||
this.buchID = buchID;
|
||||
this.autor = autor;
|
||||
this.titel = titel;
|
||||
this.erscheinungsjahr = erscheinungsjahr;
|
||||
this.genre = genre;
|
||||
}
|
||||
|
||||
public String getBuchID() {
|
||||
return buchID;
|
||||
}
|
||||
|
||||
public String getAutor() {
|
||||
return autor;
|
||||
}
|
||||
|
||||
public int getErscheinungsjahr() {
|
||||
return erscheinungsjahr;
|
||||
}
|
||||
|
||||
public String getGenre() {
|
||||
return genre;
|
||||
}
|
||||
|
||||
public String getTitel() {
|
||||
return titel;
|
||||
}
|
||||
}
|
||||
49
src/main/java/Main.java
Normal file
49
src/main/java/Main.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import java.util.Random;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Buch[] buchListe = new Buch[26];
|
||||
|
||||
for (int i = 0; i < buchListe.length; i++) {
|
||||
buchListe[i] = new Buch(randStr(5), randStr(10), randStr(5), new Random().nextInt(1), randStr(5));
|
||||
}
|
||||
|
||||
Buch[] sorted = sortBuecher(buchListe);
|
||||
|
||||
for (Buch buch : sorted) {
|
||||
System.out.println(buch.getAutor() + ", " + buch.getErscheinungsjahr() + ", " + buch.getTitel());
|
||||
}
|
||||
}
|
||||
|
||||
public static Buch[] sortBuecher(Buch[] buchListe) {
|
||||
for (int i = 1; i < buchListe.length; i++) {
|
||||
for (int j = 0; j < buchListe.length - i; j++) {
|
||||
if (buchListe[j].getAutor().compareTo(buchListe[j + 1].getAutor()) > 0)
|
||||
swap(buchListe, j, j + 1);
|
||||
|
||||
if (buchListe[j].getAutor().compareTo(buchListe[j + 1].getAutor()) == 0 && buchListe[j].getErscheinungsjahr() > buchListe[j + 1].getErscheinungsjahr())
|
||||
swap(buchListe, j, j + 1);
|
||||
|
||||
if (buchListe[j].getAutor().compareTo(buchListe[j + 1].getAutor()) == 0 && buchListe[j].getErscheinungsjahr() == buchListe[j + 1].getErscheinungsjahr() && buchListe[j].getTitel().compareTo(buchListe[j + 1].getTitel()) > 0)
|
||||
swap(buchListe, j, j + 1);
|
||||
}
|
||||
}
|
||||
return buchListe;
|
||||
}
|
||||
|
||||
public static Buch[] swap(Buch[] buchListe, int i, int j) {
|
||||
Buch temp = buchListe[i];
|
||||
buchListe[i] = buchListe[j];
|
||||
buchListe[j] = temp;
|
||||
return buchListe;
|
||||
}
|
||||
|
||||
public static String randStr(int length) {
|
||||
String letters = "abcdefghijklmnopqrstuvwxyz";
|
||||
String random = "";
|
||||
for (int i = 0; i < length; i++) {
|
||||
random += letters.toCharArray()[new Random().nextInt(2454) % letters.length()];
|
||||
}
|
||||
return random;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue