Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package phonebook;
- /**
- * Document : PhoneBook Created on : 20/10/2014, 13:00:57 Author : Admin
- */
- public class PhoneBook
- {
- private Contact[] list;
- private int count;
- private static final int MAX_CONTACT = 40;
- public PhoneBook()
- {
- count = 0;
- list = new Contact[MAX_CONTACT];
- }
- public void addContact(String name, String phone)
- {
- int i = 0;
- while(i < count && !name.equals(list[i].getN()))
- {
- i++;
- }
- if(i < count)
- {
- list[i].setP(phone);
- }
- else
- {
- if(count == list.length)
- {
- Contact[] tmp = new Contact[MAX_CONTACT];
- for(int j = 0; j < list.length; j++)
- {
- tmp[j] = list[j];
- }
- list = tmp;
- list[count] = new Contact(name, phone);
- count++;
- }
- }
- }
- public void delContact(String name)
- {
- for(int i = 0; i < count; i++)
- {
- if(list[i].getN().equals(name))
- {
- for(int j = i; j < count - 1; j++)
- {
- Contact temp = list[j];
- list[j] = list[j + 1];
- list[j + 1] = temp;
- }
- list[count - 1] = null;
- count--;
- }
- }
- }
- public String getPhone(String name)
- {
- for(int i = 0; i < count; i++)
- {
- if(list[i].equals(name))
- {
- return list[i].getP();
- }
- }
- return null;
- }
- public String[] getAllContactsNames()
- {
- String[] names = new String[count];
- for(int i = 0; i < count; i++)
- {
- names[i] = list[i].getN();
- }
- return names;
- }
- @Override
- public String toString()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement