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"); } }
public void Delete(MobilePhone m) { if (size == 0) System.out.println("This set is empty"); Node dummy = head; if (dummy.mphone.number() == m.number()) { dummy = dummy.next; head = dummy; return; } while (dummy.next != null) { if (dummy.next.mphone.number() == m.number()) { dummy.next = dummy.next.next; System.out.println("deleted phone with no. " + m.number()); return; } dummy = dummy.next; } System.out.println("no such item to delete"); }
public void Insert(MobilePhone m) { Node newnode = new Node(); MobilePhone mp = new MobilePhone(m.number()); newnode.mphone = mp; newnode.mphone.switchOn(); newnode.next = head; head = newnode; size++; }
private static void addNewContact() { System.out.println("Enter new contact name:"); String name = scanner.nextLine(); System.out.println("Enter phone number:"); String phone = scanner.nextLine(); Contacts newContact = Contacts.createContact(name, phone); if (mobilePhone.addNewContact(newContact)) { System.out.println("New contact added: " + name + ", phone " + phone); } else { System.out.println("Cannot add, " + name + " name is already on file"); } }
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"); } }
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()); }
public static void main(String[] args) { /* - Menu Options: quit, print list of contacts, add new contact, update existing contact, remove contact, search/find contact */ boolean quit = false; startPhone(); printActions(); while (!quit) { System.out.println("\nEnter action: (6 to show available actions)"); int action = scanner.nextInt(); scanner.nextLine(); switch (action) { case 0: System.out.println("\nShutting down..."); quit = true; break; case 1: mobilePhone.printContacts(); break; case 2: addNewContact(); break; case 3: updateContact(); break; case 4: removeContact(); break; case 5: queryContact(); break; case 6: printActions(); break; } } }
public void launch() { MobilePhone myphone = new SmartPhone("iPhone"); myphone.call("020 1111 5000"); myphone.ringAlarm("Brr, brr"); myphone.call("020 2222 5000"); myphone.playGame("Tetris"); myphone.call("020 3333 5000"); SmartPhone correctPhoneType = (SmartPhone) myphone; correctPhoneType.browseWeb("www.bbk.ac.uk"); myphone.call("020 4444 5000"); System.out.println(correctPhoneType.findPosition()); myphone.call("020 5555 5000"); System.out.println("My phone is a " + myphone.getBrand()); myphone.call("00 1 234 5678"); myphone.printLastNumbers(); }