JAVA SUCKS
public class addbook2
{
public static void main(String[] args)
{
String[] name, phone, add, age;
String delete_name;
String sctr;
name=new String[10];
phone=new String[10];
add=new String[10];
age=new String[10];
char ans;
int n, nctr=0, lctr=0, searchctr=0, delctr=0, delctr2=10, dctr=0;
do
{System.out.println("\t\t\tWelcome to My AddressBook");
System.out.println();
System.out.println("\t\t\t Choose Your Action");
System.out.println();
System.out.println("\t\t\t[1]Add Contact");
System.out.println("\t\t\t[2]Delete Contact");
System.out.println("\t\t\t[3]Display Contact List");
System.out.println("\t\t\t[4]Search for Contact");
System.out.println("\t\t\t[5]Exit Program");
System.out.println();
System.out.print("\t\t\tChoice:");
n=ConsoleIn.readlnInt();
if(n == 1) // add contact option
{ ans='y';
while(ans=='y'||ans=='Y')
{if (nctr<10)
{
System.out.print("Enter Name: ");
name[nctr]=ConsoleIn.readln();
System.out.print("Enter Address: ");
add[nctr]=ConsoleIn.readln();
System.out.print("Enter Age: ");
age[nctr]=ConsoleIn.readln();
System.out.print("Enter Contact: ");
phone[nctr]=ConsoleIn.readln();
System.out.println("CONTACT ADDED!!!");
nctr=nctr+1;
ans = 'n';
}
if (nctr>=10)
{ ans='n';
System.out.println("memory full!!!");}
System.out.println ("add a new contact?(y/n)");
ans=ConsoleIn.readlnNonwhiteChar();}
} //end of add contact option
if (n==2) //delete option
{
dctr=0;
System.out.println("Delete Contact: ");
System.out.println("Enter name of contact to be deleted: ");
delete_name=ConsoleIn.readln();
while(dctr
{
if (delete_name.equals(name[dctr]))
{ delctr = dctr;
nctr--;
while(dctr
{ name[dctr]=name[dctr+1];
add[dctr]=add[dctr+1];
age[dctr]=age[dctr+1];
phone[dctr]=phone[dctr+1];dctr++;
} dctr++;
}dctr++;
}//end while
System.out.println("Deleted!");
}//end of delete option
if(n == 3) // display list option
{ lctr=0;
while(lctr
System.out.println("name:"+name[lctr]);
System.out.println("address:"+add[lctr]);
System.out.println("age:"+age[lctr]);
System.out.println("number:"+phone[lctr]);
System.out.println();
lctr=lctr+1;
}
} //end of display option
if (n == 4) // search name option
{
System.out.println("Search Name: ");
sctr=ConsoleIn.readln();
searchctr = 0;
while(searchctr
{
if (sctr.equals(name[searchctr]))
{
System.out.println();
System.out.println("Name: "+name[searchctr]);
System.out.println("Address: "+add[searchctr]);
System.out.println("Age: "+age[searchctr]);
System.out.println("Contact: "+phone[searchctr]);
}
searchctr=searchctr+1;
}// end of search option
}
}while (n!=5);
}
}
{
public static void main(String[] args)
{
String[] name, phone, add, age;
String delete_name;
String sctr;
name=new String[10];
phone=new String[10];
add=new String[10];
age=new String[10];
char ans;
int n, nctr=0, lctr=0, searchctr=0, delctr=0, delctr2=10, dctr=0;
do
{System.out.println("\t\t\tWelcome to My AddressBook");
System.out.println();
System.out.println("\t\t\t Choose Your Action");
System.out.println();
System.out.println("\t\t\t[1]Add Contact");
System.out.println("\t\t\t[2]Delete Contact");
System.out.println("\t\t\t[3]Display Contact List");
System.out.println("\t\t\t[4]Search for Contact");
System.out.println("\t\t\t[5]Exit Program");
System.out.println();
System.out.print("\t\t\tChoice:");
n=ConsoleIn.readlnInt();
if(n == 1) // add contact option
{ ans='y';
while(ans=='y'||ans=='Y')
{if (nctr<10)
{
System.out.print("Enter Name: ");
name[nctr]=ConsoleIn.readln();
System.out.print("Enter Address: ");
add[nctr]=ConsoleIn.readln();
System.out.print("Enter Age: ");
age[nctr]=ConsoleIn.readln();
System.out.print("Enter Contact: ");
phone[nctr]=ConsoleIn.readln();
System.out.println("CONTACT ADDED!!!");
nctr=nctr+1;
ans = 'n';
}
if (nctr>=10)
{ ans='n';
System.out.println("memory full!!!");}
System.out.println ("add a new contact?(y/n)");
ans=ConsoleIn.readlnNonwhiteChar();}
} //end of add contact option
if (n==2) //delete option
{
dctr=0;
System.out.println("Delete Contact: ");
System.out.println("Enter name of contact to be deleted: ");
delete_name=ConsoleIn.readln();
while(dctr
if (delete_name.equals(name[dctr]))
{ delctr = dctr;
nctr--;
while(dctr
add[dctr]=add[dctr+1];
age[dctr]=age[dctr+1];
phone[dctr]=phone[dctr+1];dctr++;
} dctr++;
}dctr++;
}//end while
System.out.println("Deleted!");
}//end of delete option
if(n == 3) // display list option
{ lctr=0;
while(lctr
System.out.println("address:"+add[lctr]);
System.out.println("age:"+age[lctr]);
System.out.println("number:"+phone[lctr]);
System.out.println();
lctr=lctr+1;
}
} //end of display option
if (n == 4) // search name option
{
System.out.println("Search Name: ");
sctr=ConsoleIn.readln();
searchctr = 0;
while(searchctr
if (sctr.equals(name[searchctr]))
{
System.out.println();
System.out.println("Name: "+name[searchctr]);
System.out.println("Address: "+add[searchctr]);
System.out.println("Age: "+age[searchctr]);
System.out.println("Contact: "+phone[searchctr]);
}
searchctr=searchctr+1;
}// end of search option
}
}while (n!=5);
}
}
Page created: August 17th 2005 01:59 AM
Page updated: August 23rd 2005 12:23 AM
