Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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){
- 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() {
- for (int i = 0; i < count; i++) {
- }
- return "PhoneBook [list=" + Arrays.toString(list) + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement