first commit

master
lutzzarske 2023-12-19 16:22:55 +01:00
commit 01fddf6973
6 changed files with 158 additions and 0 deletions

10
.classpath 100644
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
/bin/

17
.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Semesteraufgabe</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@ -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<String, Adresse> 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();
}
}

View File

@ -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";
}
}