package pers; public class menu { private pers.database db; public menu() { this.db = new database(); } public boolean main_menu() { System.out.println ( "1 Neuen Datensatz hinzufügen\n"+ "2 Alle Datensätze anzeigen\n"+ "3 Einen Datensatz ändern\n"+ "4 Einen Datensatz löschen\n"+ "5 Programm beenden"); java.io.Console console = System.console(); char choice = console.readLine ("Deine Wahl: ").charAt(0); if (choice=='1') { this.main_add(); } else if (choice=='2') { this.show_all(); } else if (choice=='3') { this.main_change(); } else if (choice=='4') { this.main_delete(); } else if (choice=='5') { return false; } else { } return true; } public void main_add() { java.io.Console console = System.console(); String name = console.readLine ("Name: "); String adress = console.readLine ("Adress: "); int phone = java.lang.Integer.parseInt( console.readLine ("Phone: ") ); pers.person myperson = new pers.person ( name, adress, phone ); this.db.add ( myperson ); } public void main_delete() { if (db.size() < 1) return; this.show_all(); java.io.Console console = System.console(); int index = java.lang.Integer.parseInt( console.readLine("Welcher Index soll gelöscht werden? ")); pers.person p = db.get( index ); char choice = console.readLine("Sind Sie sicher, dass Eintrag '" + p.getName() + "' gelöscht werden soll? (y|n) ").charAt(0); if (choice=='y') { db.remove(index); } } public void main_change() { if (db.size() < 1) return; this.show_all(); java.io.Console console = System.console(); int index = java.lang.Integer.parseInt( console.readLine("Welcher Index soll geändert werden? ")); pers.person p = db.get( index ); pers.person old=p; p.printInfo(); String name = console.readLine("Neuer Name: "); String adress = console.readLine("Neue Adresse: "); String phone = console.readLine("Neue Phone-Nummer: "); if (!name.isEmpty()) p.setName(name); if (!adress.isEmpty()) p.setAdress(adress); if (!phone.isEmpty()) p.setPhone( java.lang.Integer.parseInt( phone ) ); db.set ( old, p ); } public void show_all () { db.list(); } }