Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 AddressBook

Explanation / 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);
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote