Create a program that lets the user enter information into an address book, and
ID: 3553132 • Letter: C
Question
Create a program that lets the user enter information into an address book, and then search the names in the address book. You must store the following in the address book:
The program will allow the user to enter as many people as they want into the address book, up to 100. The user will enter an empty name to indicate they are done entering names. After that the user will enter partial names to search for people in the address book. For full credit this search should find partial names (see screenshot for examples). You program does not need to be case insensitive (i.e. it can be case sensitive). You program should display all the information for all address book entries that match the search criteria. The results should be in a chart format (see screenshot for example).
If the user enters a blank name to search for the program should end.
You must use three parallel one dimensional arrays. You must use a global constant to set the maximum number of entries in the address book to 100.
Your program must accept input in the exact order used in the screenshot below:
Explanation / Answer
import java.util.Scanner;
class Person
{
public String Name;
public String Phone;
public String Address;
public Person()
{
Name="";
Phone="";
Address="";
}
public Person(String a, String b, String c)
{
Name=a;
Phone=b;
Address=c;
}
}
class Test
{
public static void main(String args[])
{
Person[] AddressBook=new Person[100];
Scanner s=new Scanner(System.in);
int i=0;
while(true)
{
System.out.print("Enter name ( or <ENTER> if done): ");
String name=s.nextLine();
if(name.equals(""))
{
break;
}
System.out.print("Enter phone number: ");
String phone=s.nextLine();
System.out.print("Enter address: ");
String address=s.nextLine();
AddressBook[i]=new Person(name,phone,address);
i++;
if(i==100)
{
break;
}
System.out.println();
}
System.out.println();
while(true)
{
System.out.print("Enter search value: ");
String str=s.nextLine();
if(str.equals(""))
{
break;
}
System.out.println("Name Phone Address");
System.out.println("---- ----- ------");
for(int j=0;j<i;j++)
{
if(AddressBook[j].Name.contains(str))
{
System.out.println(AddressBook[j].Name+" "+AddressBook[j].Phone+" "+AddressBook[j].Address);
}
}
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.