You are on page 1of 7

Expert Answer

you will find ur answer here http://www.chegg.com/homework-help/questions-and-

answers/write-java-menu-driven-program-creates-manipulates-directory-names-telephone-

numbers-home--q3684794

Write a Java menu-driven program that creates and manipulates a directory of names, telephone

numbers, and home addresses. The following information will be stored for each person in the

directory: - Name (Last, First) - Home address (street address, city, state, zip code) - Home

telephone number Your program should be able to perform the following basic functions: -

Display the entire directory - Search and display the contents of a particular entry - Sort the

entire collection by key value (the combination of last and first names) - Delete an existing entry

- Insert an entry to the end of the directory list - Save the entire directory to a file THIS IS MY

CODE SO FAR: 1)Person class... ------------------------------------------------------------------ public

class Person { public String name; public String address; public int telephone; }

-------------------------------------------- 2) Directory class.........

---------------------------------------------------------------- import java.util.*; public class Directory

{ ArrayList personList = new ArrayList(); public static void main(String[] args) { Directory s =

new Directory(); s.getOption(); } public void getOption() { Scanner scan = new

Scanner(System.in); System.out.println("Press 1 to Add Person"); System.out.println("Press 2 to

Search Person"); System.out.println("Enter your choice"); int choice =

Integer.parseInt(scan.nextLine()); switch (choice) { case 1: addPerson(); break; case 2:

searchPerson(); break; default: System.out.println("Wrong choice"); } } public void addPerson()


{ Person A1 = new Person(); Scanner sc = new Scanner(System.in); System.out.println("Enter

name: "); A1.name = sc.nextLine(); System.out.println("Enter address: "); A1.address =

sc.nextLine(); System.out.println("Enter telephone number: "); A1.telephone =

Integer.parseInt(sc.nextLine()); personList.add(A1); getOption(); } public void searchPerson()

{ Scanner scan = new Scanner(System.in); System.out.println("Enter person's name: "); String

personName = scan.nextLine(); int flag = 0; for(int i = 0; i < 0; i++) { Person temp =

personList.get(i); if(personName.equals(temp.name)) { System.out.println("Person Found"); flag

= 1; } } if(flag == 0) { System.out.println("Person not found"); } getOption(); } }

View comments (6) 

Expert Answer

please rate - thanks

message me before rating, if any problems

//Person class

public class Person

{ public String name;

public String address;

public int telephone;

public String getName()

{return name;
}

public String toString()

{return "Name: "+name+" --Address: "+address+"--Telephone: "+telephone;

------------------------------------

import java.util.*;

public class Directory

{public static void main(String[] args)

{ ArrayList<Person> personList = new ArrayList<Person>();

int choice=getOption();

while(choice!=3)

{switch (choice)

{ case 1: addPerson(personList); break;

case 2: searchPerson(personList); break;

default: System.out.println("Wrong choice");

choice=getOption();

}
public static int getOption()

{ Scanner scan = new Scanner(System.in);

System.out.println("Press 1 to Add Person");

System.out.println("Press 2 to Search Person");

System.out.println("Press 3 to exit");

System.out.println("Enter your choice");

int choice = Integer.parseInt(scan.nextLine());

return choice;

public static void addPerson(ArrayList<Person> personList)

{ Person A1 = new Person();

Scanner sc = new Scanner(System.in);

System.out.println("Enter name: ");

A1.name = sc.nextLine();

System.out.println("Enter address: ");

A1.address = sc.nextLine();

System.out.println("Enter telephone number: ");

A1.telephone = Integer.parseInt(sc.nextLine());

personList.add(A1);

System.out.println("list="+personList);

public static void searchPerson(ArrayList<Person> personList)

{ Scanner scan = new Scanner(System.in);


Person temp = new Person();

System.out.println("Enter person's name: ");

String personName = scan.nextLine();

for(int i = 0; i < personList.size(); i++)

{ temp=personList.get(i);

if(personName.equals(temp.getName()))

{System.out.println("Person Found"+temp);

return;

System.out.println("Person not found");

}
Hide comments (2) 

Comments

o MellowCelery2106 posted 9 years ago

Would you be able to finish this program? I will add more points.

o MellowCelery2106 posted 9 years ago


Thank you very much! This was a great start to the project.

You might also like