Initial Commit
commit
199ed91fe6
|
@ -0,0 +1,2 @@
|
|||
/bin/
|
||||
.classpath
|
|
@ -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>
|
|
@ -0,0 +1,14 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=16
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=16
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
public class Data {
|
||||
|
||||
String benutzername;
|
||||
String password;
|
||||
|
||||
public String getBenutzername() {
|
||||
return benutzername;
|
||||
}
|
||||
|
||||
public void setBenutzername(String benutzername) {
|
||||
this.benutzername = benutzername;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class KontoVerwalten {
|
||||
|
||||
static HashMap<String, String> credentials = new HashMap<>();
|
||||
|
||||
public void anmelden() {
|
||||
Scanner input = new Scanner(System.in);
|
||||
Data data = new Data();
|
||||
Menue menu = new Menue();
|
||||
System.out.println("Bitte geben Sie ihren Benutzername_Passwort ein:");
|
||||
try {
|
||||
String[] in1 = input.nextLine().split(" ");
|
||||
if (in1[0].equals("9")) {
|
||||
System.out.println("Aufwiedersehen.");
|
||||
input.close();
|
||||
System.exit(0);
|
||||
} else if (credentials.containsKey(in1[1]) && credentials.get(in1[1]).equals(in1[0])) {
|
||||
data.setBenutzername(in1[0]);
|
||||
data.setPassword(in1[1]);
|
||||
menu.secondMenu(data, credentials);
|
||||
} else {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
anmelden();
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
anmelden();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void regestrieren() {
|
||||
Scanner input = new Scanner(System.in);
|
||||
Data data = new Data();
|
||||
Menue menu = new Menue();
|
||||
System.out.println("Bitte geben Sie ihren Benutzername_Passwort ein:");
|
||||
try {
|
||||
String[] in2 = input.nextLine().split(" ");
|
||||
if (in2[0].equals("9")) {
|
||||
System.out.println("Aufwiedersehen.");
|
||||
input.close();
|
||||
System.exit(0);
|
||||
} else if (credentials.containsKey(in2[1]) || credentials.containsValue(in2[0])) {
|
||||
System.out.println("Regestrierung nicht möglich!");
|
||||
System.out.println("Bitte ändern Sie Ihren Benutzername/Passwort.");
|
||||
regestrieren();
|
||||
} else {
|
||||
credentials.put(in2[1], in2[0]);
|
||||
System.out.println("Konto wurde erstellt.");
|
||||
menu.menu();
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
regestrieren();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void changePassBen(Data data) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
Menue menu = new Menue();
|
||||
System.out.println("Geben Sie ein, ob Sie Ihr [pass]Passwort oder Ihren [ben]Benutzernamen ändern wollen");
|
||||
String in3 = input.nextLine();
|
||||
try {
|
||||
if (in3.equals("8")) {
|
||||
menu.secondMenu(data, credentials);
|
||||
} else if (in3.equalsIgnoreCase("ben")) {
|
||||
System.out.println("Geben Sie den Benutzername_Passwort_neuer Benutzername des Kontos ein:");
|
||||
String[] ben = input.nextLine().split(" ");
|
||||
if (!credentials.containsKey(ben[1]) || !credentials.containsValue(ben[0])) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
changePassBen(data);
|
||||
} else if (!credentials.get(ben[1]).equals(ben[0])) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
changePassBen(data);
|
||||
} else if (ben[0].equals(ben[2])) {
|
||||
System.out.println("Neuer Benutzername kann nicht der alte Benutzername sein");
|
||||
changePassBen(data);
|
||||
} else if (credentials.containsValue(ben[2]) || credentials.containsKey(ben[2])) {
|
||||
System.out.println("Benutzername ungültig");
|
||||
changePassBen(data);
|
||||
} else {
|
||||
credentials.replace(ben[1], ben[0], ben[2]);
|
||||
System.out.println("Benutzername wurde geändert");
|
||||
data.setBenutzername(ben[2]);
|
||||
menu.secondMenu(data, credentials);
|
||||
}
|
||||
} else if (in3.equalsIgnoreCase("pass")) {
|
||||
System.out.println("Geben Sie den Benutzername_Passwort_neues Passwort des Kontos ein:");
|
||||
String[] pass = input.nextLine().split(" ");
|
||||
if (!credentials.containsKey(pass[1]) || !credentials.containsValue(pass[0])) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
changePassBen(data);
|
||||
} else if (!credentials.get(pass[1]).equals(pass[0])) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
changePassBen(data);
|
||||
} else if (pass[1].equals(pass[2])) {
|
||||
System.out.println("Neues Passwort kann nicht das alte Passwort sein");
|
||||
changePassBen(data);
|
||||
} else if (credentials.containsKey(pass[2]) || credentials.containsValue(pass[2])) {
|
||||
System.out.println("Passwort ungültig");
|
||||
changePassBen(data);
|
||||
} else {
|
||||
credentials.remove(pass[1]);
|
||||
credentials.put(pass[2], pass[0]);
|
||||
System.out.println("Passwort wurde geändert");
|
||||
data.setPassword(pass[2]);
|
||||
menu.secondMenu(data, credentials);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
changePassBen(data);
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
changePassBen(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void deleteKonto(Data data) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
Menue menu = new Menue();
|
||||
System.out.println("Bitte Geben Sie den Benutzername_Passwort des zu löschenden Kontos ein: ");
|
||||
try {
|
||||
String[] in4 = input.nextLine().split(" ");
|
||||
if (in4[0].equals("8")) {
|
||||
menu.secondMenu(data, credentials);
|
||||
} else if (!credentials.containsKey(in4[1]) || !credentials.containsValue(in4[0])) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
deleteKonto(data);
|
||||
} else if (!credentials.get(in4[1]).equals(in4[0])) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
deleteKonto(data);
|
||||
} else {
|
||||
credentials.remove(in4[1], in4[0]);
|
||||
System.out.println("Konto von " + in4[0] + " gelöscht.");
|
||||
if (data.getBenutzername().equals(in4[0])) {
|
||||
System.out.println("Abmeldung, da Angemeldetes Konto gelöscht wurde");
|
||||
menu.menu();
|
||||
} else {
|
||||
menu.secondMenu(data, credentials);
|
||||
}
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
System.out.println("Fehler bei den Angaben!");
|
||||
deleteKonto(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Menue menu = new Menue();
|
||||
menu.menu();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Menue {
|
||||
|
||||
public void menu() {
|
||||
Scanner input = new Scanner(System.in);
|
||||
KontoVerwalten verwalten = new KontoVerwalten();
|
||||
System.out.println("_ -> Leerzeichen");
|
||||
System.out.println("------Menü------");
|
||||
System.out.println("[1] Anmelden");
|
||||
System.out.println("[2] Registrieren");
|
||||
System.out.println("[9] Beenden");
|
||||
String ans = input.nextLine();
|
||||
if (ans.equals("9")) {
|
||||
System.out.println("Aufwiedersehen.");
|
||||
input.close();
|
||||
System.exit(0);
|
||||
} else if (ans.equals("1")) {
|
||||
verwalten.anmelden();
|
||||
} else if (ans.equals("2")) {
|
||||
verwalten.regestrieren();
|
||||
} else {
|
||||
System.out.println("Eingabe konnte nicht erkannt werden.");
|
||||
menu();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void secondMenu(Data data, HashMap<String, String> credentials) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
KontoVerwalten verwalten = new KontoVerwalten();
|
||||
System.out.println("Herzlich Willkommen: " + data.getBenutzername());
|
||||
System.out.println("------Menü------");
|
||||
System.out.println("[1] Passwort/Benutzername ändern");
|
||||
System.out.println("[2] Alle gespeicherten Konten ausgeben");
|
||||
System.out.println("[3] Konto löschen");
|
||||
System.out.println("[8] Zurück/Abmelden");
|
||||
String answer = input.nextLine();
|
||||
if (answer.equals("8")) {
|
||||
menu();
|
||||
} else if (answer.equals("1")) {
|
||||
verwalten.changePassBen(data);
|
||||
} else if (answer.equals("2")) {
|
||||
int j = 1;
|
||||
for (String s : credentials.keySet()) {
|
||||
System.out.println("Konto " + j++ + ": Benutzername -> " + credentials.get(s) + " | Passwort -> " + s);
|
||||
}
|
||||
secondMenu(data, credentials);
|
||||
} else if (answer.equals("3")) {
|
||||
verwalten.deleteKonto(data);
|
||||
} else {
|
||||
System.out.println("Eingabe konnte nicht erkannt werden");
|
||||
secondMenu(data, credentials);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue