/*--------------------------------------------------------------------------
AdressBookConsoleDemo class
*****************
Version: 07/07/2008
"*****************
Note: add, edit and searching the addressbook
//----------------------------------------------------------------------*/
public class AdressBookConsoleDemo {
static int hold = 1;
static String[][] addressBookHolder = new String[10000][4];
public static void main(String[] args){
AdressBookConsoleDemo ABCD = new AdressBookConsoleDemo();
ABCD.addEntry("Mr. ", "Ben", "1111111111", "Javaprogrammingforums.com");
ABCD.addEntry("Mr. ", "Javaforums", "0000000000", "Java-forums.net");
ABCD.addEntry("Mr. ", "Duke", "+00 123456", "World");
ABCD.addEntry("Mr. ", "Someone", "+0012233", "right here!");
System.out.println("Addressbook: ");
ABCD.showAddressBook();
System.out.println("Edited addressbook: ");
ABCD.editEntry(3, "Mr. ", "Duke nukem", "+00 123456", "Behind pc");
ABCD.showAddressBook();
System.out.println("Select one person from addressbook: ");
ABCD.showAddressBook(2);
System.out.println("Search one person from addressbook: ");
ABCD.searchAddressBook("Ark");
ABCD.searchAddressBook("JavafDorums");
}
public void addEntry(String salutation, String name, String telephoneNumber, String address){
addressBookHolder[hold][0] = salutation;
addressBookHolder[hold][1] = name;
addressBookHolder[hold][2] = telephoneNumber;
addressBookHolder[hold][3] = address;
hold++;
}
public void editEntry(int id, String salutation, String name, String telephoneNumber, String address){
addressBookHolder[id][0] = salutation;
addressBookHolder[id][1] = name;
addressBookHolder[id][2] = telephoneNumber;
addressBookHolder[id][3] = address;
}
//delete an entry from the addressbook
public void deletEntry(String name){}
public void showAddressBook(int id){
System.out.println();
System.out.println("Record number: " + id);
System.out.println( "Salutation: " + addressBookHolder[id][0] + "\n" +
"Name: "+ addressBookHolder[id][1] + "\n" +
"TelephoneNumber: "+ addressBookHolder[id][2] + "\n" +
"Address: " + addressBookHolder[id][3]);
System.out.println();
}
public void showAddressBook(){
System.out.println();
for ( int i = 1; i < addressBookHolder.length; i++){
if(addressBookHolder[i][0] !=null){
System.out.println("Record number: " + i);
System.out.println( "Salutation: " + addressBookHolder[i][0] + "\n" +
"Name: "+ addressBookHolder[i][1] + "\n" +
"TelephoneNumber: "+ addressBookHolder[i][2] + "\n" +
"Address: " + addressBookHolder[i][3]);
System.out.println();
}
}
}
//searchAddressBook is broken when there are no results. I didn't bothered myself to fix this.
public void searchAddressBook(String name){
int search = 1;
for ( int i = 1; i < addressBookHolder.length; i++){
try{
if(addressBookHolder[i][1].equals(name)){
showAddressBook(search);
break;
}
}
catch(NullPointerException NPE){}
search++;
}
}
}