Extra Credit) Write an AddressBook class that manages a collection of person obj
ID: 3841977 • Letter: E
Question
Extra Credit) Write an AddressBook class that manages a collection of person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, or search for a Person object in the address book The add method should add a person object to the address book. The delete method should remove the specified person object from the address book. The search method that searches the address book for a specified person and prints the list of persons matching the specified criteria. The search can be done either by first name, last name, or person id. write a main program class to test your AddressBookExplanation / Answer
Since you havent given what person object has i am assuming it has id, first name and last name.
Class Person
{
int id;
String firstname;
String lastname;
}
Class AddressBook
{
List<Person> persons= new ArrayList<>();
void addPerson(Person p)
{
this.persons.add(p);
}
int findPerson(int id)
{
for(int i=0;i<persons.size();i++)
{
if(i.id==id)
{
System.out.println(person[i]);
}
}
}
int findPerson(int firstname)
{
for(int i=0;i<persons.size();i++)
{
if(i.firstname.equals(firstname)
{
System.out.println(person[i]);
}
}
}
int findPerson(int lastname)
{
for(int i=0;i<persons.size();i++)
{
if(i.lastname.equals(lastname)
{
System.out.println(person[i]);
}
}
}
void removePerson(Person p)
{
this.persons.remove(p);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.