commit ef8d621a5820da371ef4e445028841264a9ff108 Author: Marc Michalsky Date: Fri Apr 10 02:00:00 2020 +0200 initial commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -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/ diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..146ab09 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1386f2e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2f2ab75 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3b566e2 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Kino +![Bild](img/Kino.png) \ No newline at end of file diff --git a/img/Kino.png b/img/Kino.png new file mode 100644 index 0000000..0866704 Binary files /dev/null and b/img/Kino.png differ diff --git a/src/gfn/marc/Sitzplatz.java b/src/gfn/marc/Sitzplatz.java new file mode 100644 index 0000000..20cacd6 --- /dev/null +++ b/src/gfn/marc/Sitzplatz.java @@ -0,0 +1,24 @@ +package gfn.marc; + +public class Sitzplatz { + + private final int nummer; + private boolean status; // true wenn frei, false wenn belegt + + public Sitzplatz(int nummer, boolean status) { + this.nummer = nummer; + this.status = status; + } + + public int getNummer() { + return nummer; + } + + public boolean isStatus() { + return status; + } + + public void setStatus(boolean status) { + this.status = status; + } +} diff --git a/src/gfn/marc/version1/Main_v1.java b/src/gfn/marc/version1/Main_v1.java new file mode 100644 index 0000000..ab8a952 --- /dev/null +++ b/src/gfn/marc/version1/Main_v1.java @@ -0,0 +1,155 @@ +package gfn.marc.version1; + +/* + Version 1: "normale" Arrays +*/ + +import gfn.marc.Sitzplatz; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public class Main_v1 { + + // VORBEREITUNG + // Array für Sitzplan erstellen + static Sitzplatz[][] sitzplan = new Sitzplatz[7][30]; + + public static void main(String[] args) { + + // Sitzplan-Array füllen + for (int i = 0; i < sitzplan.length; i++) { + for (int j = 0; j < sitzplan[i].length; j++) { + sitzplan[i][j] = new Sitzplatz(((i + 1) * 100 + (j + 1)), false); + } + } + + // Hilfs-Array für freie Plätze (wie in der Vorgabe) + int[] alleFreienSitzplaetze = {102, 203, 204, 207, 208, 209, 303, 304, 305, 306, 307, 308}; + + // Freie Plätze in Sitzplan-Array eintragen + try { + for (int sitzplatz : alleFreienSitzplaetze) { + int i = (sitzplatz / 100) - 1; + int j = (sitzplatz % 10) - 1; + sitzplan[i][j].setStatus(true); + } + } catch (ArrayIndexOutOfBoundsException aioobe) { + System.err.println("Fehlerhafte Sitzplatznummer in Array \"alleFreienSitzplaetze\" eingetragen!"); + System.exit(0); + } + + // LÖSUNG + // Gewünschte Sitzplatzanzahl eingeben + boolean reservierung = true; + Scanner eingabe = new Scanner(System.in); + int anzahlSitze = 0; + System.out.println("Bitte geben Sie die gewünschte Anzahl von Sitzplätzen ein! (1 - 30)"); + + // Eingabe überprüfen + while (true) { + try { + anzahlSitze = eingabe.nextInt(); + if (anzahlSitze < 1 || anzahlSitze > 30) { + System.err.println("Die eingegebene Zahl ist ungültig!"); + System.err.println("Bitte geben Sie eine Zahl zwischen 1 und 30 ein."); + } else { + break; + } + } catch (InputMismatchException ime) { + System.err.println("Bitte geben Sie eine Zahl ein!"); + eingabe.next(); + } + + } + + // Freie Sitzplätze mit der Methode freieSitze() ermitteln + int freierSitzplatz = freieSitze(anzahlSitze); + + // Ausgabe der Nummern der freien Sitzplätze + if (freierSitzplatz != 0 && anzahlSitze > 1) { + System.out.print("Folgende Sitzplätze können für Sie reserviert werden: "); + for (int i = 0; i < anzahlSitze; i++) { + if (i < anzahlSitze - 1) { + System.out.print(freierSitzplatz + i + ", "); + } else { + System.out.print(freierSitzplatz + i); + } + } + System.out.println(); + } else if (freierSitzplatz != 0) { + System.out.println("Folgender Sitzplatz kann für Sie reserviert werden: " + freierSitzplatz); + + // Falls gewünschte Anzahl von freien Sitzplätzen nicht vorhanden + } else { + System.out.println(anzahlSitze > 1 ? "Leider konnten wir für Sie nicht die gewünschte Anzahl freier " + + "Sitzplätze reservieren." : "Leider haben wir derzeit keinen freien Sitzplatz."); + reservierung = false; + } + + // Abfrage "Möchten Sie reservieren?" mit Überprüfung der Eingabe + while (reservierung) { + System.out.println("Möchten Sie reservieren? (j/n)"); + String auswahl = eingabe.next().trim().toLowerCase(); + + // Wenn ja ("j") + if (auswahl.matches("j")) { + + for (int i = 0; i < anzahlSitze; i++) { + for (int j = 0; j < sitzplan.length; j++) { + for (int k = 0; k < sitzplan[i].length; k++) { + if (freierSitzplatz + i == sitzplan[j][k].getNummer()) { + sitzplan[j][k].setStatus(false); + } + } + } + } + + System.out.println(anzahlSitze > 1 ? "Die Sitzplätze wurden für Sie reserviert!" : + "Der Sitzplatz wurde für Sie reserviert!"); + + reservierung = false; + + // Wenn nein ("n") + } else if (auswahl.matches("n")) { + reservierung = false; + + // Wenn Eingabe ungültig + } else { + System.err.println("Eingabe ungültig!"); + } + } + + System.out.println("Vielen Dannk für Ihren Besuch und auf Wiedersehen!"); + + // Übrige freie Sitzplätze + System.out.println("\nÜbrige freie Sitzplätze: "); + for (int i = 0; i < sitzplan.length; i++) { + for (int j = 0; j < sitzplan[i].length; j++) { + if (sitzplan[i][j].isStatus()) { + System.out.print(sitzplan[i][j].getNummer() + " "); + } + } + } + System.out.println(); + + } + + static int freieSitze(int anzahlSitze) { + int zaehler = 0; + for (int i = 0; i < sitzplan.length; i++) { + for (int j = 0; j < sitzplan[i].length; j++) { + if (sitzplan[i][j].isStatus()) { + zaehler++; + } else { + zaehler = 0; + } + if (zaehler >= anzahlSitze) { + return sitzplan[i][j - (zaehler - 1)].getNummer(); + } + } + zaehler = 0; + } + return 0; + } +} diff --git a/src/gfn/marc/version2/Main_v2.java b/src/gfn/marc/version2/Main_v2.java new file mode 100644 index 0000000..5c4666f --- /dev/null +++ b/src/gfn/marc/version2/Main_v2.java @@ -0,0 +1,143 @@ +package gfn.marc.version2; + +/* + Version 2: ArrayLists +*/ + +import gfn.marc.Sitzplatz; + +import java.util.*; + +public class Main_v2 { + + // VORBEREITUNG + // ArrayList für Sitzplan erstellen + static ArrayList sitzplan = new ArrayList<>(210); + + public static void main(String[] args) { + + // Sitzplan-ArrayList füllen + for (int i = 0; i < 7; i++) { + for (int j = 0; j < 30; j++) { + sitzplan.add(new Sitzplatz(((i + 1) * 100 + (j + 1)), false)); + } + } + + // Hilfs-HashSet für freie Plätze (wie in der Vorgabe) + HashSet alleFreienSitzplaetze = new HashSet + (Arrays.asList(102, 203, 204, 207, 208, 209, 303, 304, 305, 306, 307, 308)); + + // Freie Plätze in Sitzplan-Array eintragen + for (Sitzplatz sitzplatz : sitzplan) { + if (alleFreienSitzplaetze.contains(sitzplatz.getNummer())) { + sitzplatz.setStatus(true); + } + } + + // LÖSUNG + // Gewünschte Sitzplatzanzahl eingeben + boolean reservierung = true; + Scanner eingabe = new Scanner(System.in); + int anzahlSitze = 0; + System.out.println("Bitte geben Sie die gewünschte Anzahl von Sitzplätzen ein! (1 - 30)"); + + // Eingabe überprüfen + while (true) { + try { + anzahlSitze = eingabe.nextInt(); + if (anzahlSitze < 1 || anzahlSitze > 30) { + System.err.println("Die eingegebene Zahl ist ungültig!"); + System.err.println("Bitte geben Sie eine Zahl zwischen 1 und 30 ein."); + } else { + break; + } + } catch (InputMismatchException ime) { + System.err.println("Bitte geben Sie eine Zahl ein!"); + eingabe.next(); + } + + } + + // Freie Sitzplätze mit der Methode freieSitze() ermitteln + int freierSitzplatz = freieSitze(anzahlSitze); + + // Ausgabe der Nummern der freien Sitzplätze + if (freierSitzplatz != 0 && anzahlSitze > 1) { + System.out.print("Folgende Sitzplätze können für Sie reserviert werden: "); + for (int i = 0; i < anzahlSitze; i++) { + if (i < anzahlSitze - 1) { + System.out.print(freierSitzplatz + i + ", "); + } else { + System.out.print(freierSitzplatz + i); + } + } + System.out.println(); + } else if (freierSitzplatz != 0) { + System.out.println("Folgender Sitzplatz kann für Sie reserviert werden: " + freierSitzplatz); + + // Falls gewünschte Anzahl von freien Sitzplätzen nicht vorhanden + } else { + System.out.println(anzahlSitze > 1 ? "Leider konnten wir für Sie nicht die gewünschte Anzahl freier " + + "Sitzplätze reservieren." : "Leider haben wir derzeit keinen freien Sitzplatz."); + reservierung = false; + } + + // Abfrage "Möchten Sie reservieren?" mit Überprüfung der Eingabe + while (reservierung) { + System.out.println("Möchten Sie reservieren? (j/n)"); + String auswahl = eingabe.next().trim().toLowerCase(); + + // Wenn ja ("j") + if (auswahl.matches("j")) { + + for (int i = 0; i < anzahlSitze; i++) { + for (Sitzplatz sitzplatz : sitzplan) { + if (freierSitzplatz + i == sitzplatz.getNummer()) { + sitzplatz.setStatus(false); + } + } + } + + System.out.println(anzahlSitze > 1 ? "Die Sitzplätze wurden für Sie reserviert!" : + "Der Sitzplatz wurde für Sie reserviert!"); + + reservierung = false; + + // Wenn nein ("n") + } else if (auswahl.matches("n")) { + reservierung = false; + + // Wenn Eingabe ungültig + } else { + System.err.println("Eingabe ungültig!"); + } + } + + System.out.println("Vielen Dannk für Ihren Besuch und auf Wiedersehen!"); + + // OpÜbrige freie Sitzplätze + System.out.println("\nÜbrige freie Sitzplätze: "); + for (Sitzplatz sitzplatz : sitzplan) { + if (sitzplatz.isStatus()) { + System.out.print(sitzplatz.getNummer() + " "); + } + } + System.out.println(); + + } + + static int freieSitze(int anzahlSitze) { + int zaehler = 0; + for (int i = 0; i < sitzplan.size(); i++) { + if (sitzplan.get(i).isStatus()) { + zaehler++; + } else { + zaehler = 0; + } + if (zaehler == anzahlSitze) { + return sitzplan.get(i - (zaehler - 1)).getNummer(); + } + } + return 0; + } +}