private static void queryContact() { System.out.println("Enter existing contact name: "); String name = scanner.nextLine(); Contacts existingContactRecord = mobilePhone.queryContact(name); if (existingContactRecord == null) { System.out.println("Contact not found"); return; } System.out.println( "Name: " + existingContactRecord.getContactName() + ", phone number is " + existingContactRecord.getPhoneNumber()); }
private static void removeContact() { System.out.println("Enter existing contact name: "); String name = scanner.nextLine(); Contacts existingContactRecord = mobilePhone.queryContact(name); if (existingContactRecord == null) { System.out.println("Contact not found"); return; } if (mobilePhone.removeContact(existingContactRecord)) { System.out.println("Successfully deleted"); } else { System.out.println("Error deleting contact"); } }
private static void updateContact() { System.out.println("Enter existing contact name: "); String name = scanner.nextLine(); Contacts existingContactRecord = mobilePhone.queryContact(name); if (existingContactRecord == null) { System.out.println("Contact not found"); return; } System.out.println("Enter new contact name: "); String newName = scanner.nextLine(); System.out.println("Enter new contact phone number: "); String newNumber = scanner.nextLine(); Contacts newContact = Contacts.createContact(newName, newNumber); if (mobilePhone.updateContact(existingContactRecord, newContact)) { System.out.println("Successfully updated record"); } else { System.out.println("Error updating record"); } }