commit 01fddf6973d24137eb3fccc7f6eb549c8b8c76a6 Author: lutzzarske Date: Tue Dec 19 16:22:55 2023 +0100 first commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f00af9b --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..dd44a67 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Semesteraufgabe + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/src/semesteraufgabe/Addressverwaltung.java b/src/semesteraufgabe/Addressverwaltung.java new file mode 100644 index 0000000..16bda01 --- /dev/null +++ b/src/semesteraufgabe/Addressverwaltung.java @@ -0,0 +1,103 @@ +package semesteraufgabe; + +import java.util.HashMap; +import java.util.Scanner; + +public class Addressverwaltung { + public static Scanner sc = new Scanner(System.in); + public static Adresse einzeladresse = new Adresse(); + public static HashMap adressen = new HashMap<>(); + + public static void main(String[] args) { + + askforAction(); + } + + public static void askforAdress() { + Adresse einzeladresse = new Adresse(); + + System.out.println("Name: "); + einzeladresse.name = richtigschreiben(sc.nextLine()); + System.out.println("Straße: "); + einzeladresse.straße = richtigschreiben(sc.nextLine()); + System.out.println("Hausnummer: "); + einzeladresse.hausnummer = Integer.parseInt(sc.nextLine()); + System.out.println("Postleitzahl: "); + einzeladresse.postleitzahl = Integer.parseInt(sc.nextLine()); + System.out.println("Stadt: "); + einzeladresse.stadt = richtigschreiben(sc.nextLine()); + System.out.println("Land: "); + einzeladresse.land = richtigschreiben(sc.nextLine()); + + adressen.put(einzeladresse.name, einzeladresse); + } + + public static void askforAction() { + while (true) { + System.out.println("Was möchtest du tun? (Adresse hinzufügen >h<, Adresse suchen >s<, Adresse löschen >l<, beenden >b<)"); + String input = sc.nextLine(); + String input2 = null; + + if (input.equalsIgnoreCase("h")) { + askforAdress(); + } + else if (input.equalsIgnoreCase("s")) { + System.out.println("Name: "); + input2 = richtigschreiben(sc.nextLine()); + if (adressen.containsKey(input2)) { + System.out.println(adressen.get(input2).toString()); + } else { + System.out.println(input2 + " wurde nicht gefunden. \n"); + } + } else if(input.equalsIgnoreCase("l")){ + System.out.println("Welche Adresse möchtest du löschen?"); + input2 = richtigschreiben(sc.nextLine()); + if (adressen.containsKey(input2)) { + System.out.println(adressen.get(input2).toString() + "\nMöchtest du diese Adresse löschen? >j< >n<"); + String antwort = sc.nextLine(); + + if (antwort.equals("j")) { + adressen.remove(input2); + System.out.println(input2 + " wurde gelöscht.\n"); + } + else if (antwort.equals("n")) { + System.out.println("Vorgang wurde abgebrochen."); + } + else { + System.out.println("Ungültiger Befehl\n"); + } + + } + else if (!adressen.containsKey(input2)) { + System.out.println("\nDie Adresse von " + input2 + " existiert nicht, also kann sie nicht gelöscht werden.\n"); + } + } + + + else if (input.equalsIgnoreCase("b")) { + System.out.println("\nProgramm wurde beendet. Bis zum nächsten Mal :)"); + sc.close(); + return; + } else { + System.out.println("Eingabe nicht erkannt, bitte erneut versuchen."); + } + } + } + + public static String richtigschreiben(String a) { + String result = ""; + + if (!a.isEmpty() && a.contains(" ")) { + String[] words = a.split(" "); + + for (String word : words) { + if (!word.isEmpty()) { + result += Character.toUpperCase(word.charAt(0)) + word.substring(1) + " "; + } + } + } else if (!a.contains(" ")) { + result = Character.toUpperCase(a.charAt(0)) + a.substring(1); + } + return result.trim(); + } +} diff --git a/src/semesteraufgabe/Adresse.java b/src/semesteraufgabe/Adresse.java new file mode 100644 index 0000000..69d66d5 --- /dev/null +++ b/src/semesteraufgabe/Adresse.java @@ -0,0 +1,25 @@ +package semesteraufgabe; + +public class Adresse { + public String name; + public String straße; + public int hausnummer; + public int postleitzahl; + public String stadt; + public String land; + + public Adresse(String n, String str, int h, int p, String sta, String l) { + this.name = n; + this.straße = str; + this.hausnummer = h; + this.postleitzahl = p; + this.stadt = sta; + this.land = l; + } + + public Adresse() {} + + public String toString() { + return "\n------------------\n" + name + "\n" + straße + " " + hausnummer + "\n" + postleitzahl + " " + stadt + "\n" + land + "\n------------------\n"; + } +}