Anpassung der Bezeichnung für CSV Dateien und erste CSV Datei einlesen und ausgeben

feature/GUI
Leon Maximilian Löhle 2024-12-12 21:24:54 +01:00
parent c0d96e2119
commit 53b012f6a7
7 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,83 @@
7,1,2,9,12,15,8,11,11,9,11,14,13,6,3
2,3,8,1,2,11,10,9,5,8,14,3,12,13,15
4,14,13,9,4,15,9,10,12,6,5,3,11,5,12
15,9,5,6,10,15,1,15,8,3,5,4,6,2,8
5,11,7,9,15,1,4,3,8,1,9,2,10,13,2
15,15,10,3,1,14,8,12,11,1,9,8,2,7,2
10,7,7,12,9,3,15,2,5,2,10,5,1,7,4
3,8,9,14,1,6,12,4,15,2,13,11,5,10,11
8,6,7,15,11,4,5,11,2,10,3,13,8,12,9
2,2,3,3,4,13,5,6,5,11,5,15,8,9,12
2,15,15,11,13,7,6,5,3,13,8,10,5,1,11
12,5,11,13,13,2,2,8,8,4,10,9,3,2,5
1,13,8,2,1,7,11,4,9,15,4,12,9,3,10
13,10,12,5,15,3,2,7,13,14,12,12,9,11,6
7,12,4,8,14,10,13,13,7,4,2,6,15,15,11
//Lösung
1,4
1,6
1,8
1,11
2,1
2,3
2,9
2,12
2,14
3,5
3,7
3,11
3,15
4,1
4,3
4,6
4,9
4,13
5,4
5,10
5,15
6,2
6,5
6,7
6,9
6,11
6,13
7,1
7,3
7,6
7,8
7,12
7,14
8,5
8,9
8,15
9,3
9,8
9,13
10,1
10,4
10,7
10,9
10,11
11,3
11,10
11,13
11,15
12,2
12,5
12,7
12,9
12,11
12,14
13,1
13,6
13,8
13,13
14,3
14,5
14,9
14,12
15,1
15,7
15,10
15,14
Can't render this file because it has a wrong number of fields in line 17.

View File

@ -1,4 +1,54 @@
package de.deversmann.domain;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Scanner;
public class Spielfeld {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String folderPath = Paths.get("").toAbsolutePath() + File.separator + "src" + File.separator + "Spielfelder" + File.separator;
Map<Integer, String> felder = Map.of(
1, "4x4.csv",
2, "5x5.csv",
3, "8x8_leicht.csv",
4, "8x8_medium.csv",
5, "10x10.csv",
6, "15x15.csv");
System.out.println("Verfügbare Spielfeldgrößen:");
felder.forEach((key, value) -> System.out.println(key + ": " + value.replace(".csv", "")));
System.out.println("Welche Spielfeldgröße wollen Sie bespielen?");
int wahl = sc.nextInt();
if (!felder.containsKey(wahl)) {
System.out.println("Ungültige Auswahl");
return;
}
String gewählteDatei = felder.get(wahl);
System.out.println("Sie haben die Spielfeldgröße '" + gewählteDatei.replace(".csv", "") + "' gewählt");
readCSVFile(folderPath + gewählteDatei);
}
public static void readCSVFile(String filePath) {
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
System.out.println("\nInhalt der Datei:");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
System.err.println("Fehler beim Lesen der Datei: " + e.getMessage());
}
}
}