In: Computer Science
The class Contact, shown below, which hold first names, last names, and mobile numbers.
Using the built-in Java ArrayList<Contact> contacts
Write a method
public static boolean contains(ArrayList<Contact> list, String firstOrLastName)
public class Contact { private int mobileNumber; private String firstName; private String lastName; public int getMobileNumber() { return mobileNumber; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public Contact(int mobile, String first, String last) { mobileNumber = mobile; firstName = first; lastName = last; } }
which returns a boolean indicating whether the list has a entry in which firstOrLastName is in a Contact as either name. Do not use the built-in ArrayList contains method.
import java.util.ArrayList;
public class Contact {
private int mobileNumber;
private String firstName;
private String lastName;
public int getMobileNumber() {
return mobileNumber;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public Contact(int mobile, String first, String last)
{
mobileNumber = mobile;
firstName = first;
lastName = last;
}
}
public class ContactDriver {
public static boolean contains(ArrayList<Contact> list, String firstOrLastName) {
for(Contact c:list) {
if (firstOrLastName.contains(c.getFirstName()))
return true;
if (firstOrLastName.contains(c.getLastName()))
return true;
}
return false;
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME