Advertisement
Parasect

list

Oct 7th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. public class PhoneBook
  2. {
  3.     private Contact [] list;
  4.     private int count;
  5.     private static final int MAX_CONTACT = 40;
  6.    
  7.     public PhoneBook (){
  8.         count = 0;
  9.         list = new Contact[MAX_CONTACT];
  10.    }
  11.  
  12.     public void addContact(String name, String phone){
  13.        list[count] = new Contact(name, phone);
  14.        count++;
  15.     }
  16.    
  17.     public void delContact(String name){
  18.         for (int i = 0; i < count; i++) {
  19.             if(list[i].getN().equals(name)){
  20.                
  21.                 for (int j = i; j < count-1; j++) {
  22.                 Contact temp = list[j];
  23.                 list[j] = list[j+1];
  24.                 list[j+1]=temp;
  25.                 }
  26.                 list[count-1] = null;
  27.                 count--;
  28.             }
  29.         }
  30.      }
  31.     public String getPhone(String name){
  32.     for (int i = 0; i < count; i++) {
  33.         if(list[i].equals(name)){
  34.             return list[i].getP();
  35.         }
  36.     }
  37.     return null;
  38.     }
  39.    
  40.     public String[] getAllContactsNames(){
  41.         String[] names = new String[count];
  42.         for (int i = 0; i < count; i++) {
  43.             names[i] = list[i].getN();
  44.         }
  45.         return names;
  46.     }
  47.    
  48.     @Override
  49.     public String toString() {
  50.         for (int i = 0; i < count; i++) {
  51.            
  52.         }
  53.         return "PhoneBook [list=" + Arrays.toString(list) + "]";
  54.     }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement