Question

In: Computer Science

The class Contact, shown below, which hold first names, last names, and mobile numbers. Using the...

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.

Solutions

Expert Solution

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


Related Solutions

Return the full names (first and last) of actors with “SON” in their last name, ordered...
Return the full names (first and last) of actors with “SON” in their last name, ordered by their first name. Find all the addresses where the second address (i.e. address2) is not empty (i.e., contains some text), and return these second addresses sorted. Your Professor wants you to find all the information from rental table associated with those staff (or staff ID) whose address ID is 4 (in staff table). Professor wants you to use Sub-query function. Your Professor wants...
Write a function that takes a person’s first and last names as input and (a) uses...
Write a function that takes a person’s first and last names as input and (a) uses lists to return a list of the common letters in the first and last names (the intersection). (b) uses sets to return a set that is the intersection of the characters in the first and last names. (c) uses sets to return the set that is the symmetric difference between the first and last names. please write in python program
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g....
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g. (“John”, “Doe”) that represents a class. Ask the user for a students first and last name and check if that student is a member of the class.
subjects for the next presidential election poll arecontacted using telephone numbers in which the last...
Subjects for the next presidential election poll are contacted using telephone numbers in which the last four digits are randomly selected (with replacement) find the probability that for one such phone number, the last four digits include at least one 0.
What are some generic names of meds in this class – first and second generation? What...
What are some generic names of meds in this class – first and second generation? What is the side effects of traditional first generation antihistamines? What precautions would the nurse need to consider? What generation of antihistamines are non-sedating with fewer anticholinergic effects?
Suppose a professor splits their class into two groups: students whose last names begin with A-K...
Suppose a professor splits their class into two groups: students whose last names begin with A-K and students whose last names begin with L-Z. If p1 and p2 represent the proportion of students who have an iPhone by last name, would you be surprised if p1 did not exactly equal p2? If we conclude that the first initial of a student's last name is NOT related to whether the person owns an iPhone, what assumption are we making about the...
Suppose a professor splits their class into two groups: students whose last names begin with A-K...
Suppose a professor splits their class into two groups: students whose last names begin with A-K and students whose last names begin with L-Z. If p1 and p2 represent the proportion of students who have an iPhone by last name, would you be surprised if p1 did not exactly equal p2? If we conclude that the first initial of a student's last name is NOT related to whether the person owns an iPhone, what assumption are we making about the...
Consider the equilibrium reaction shown below, which is first order with respect to each [A], [B],...
Consider the equilibrium reaction shown below, which is first order with respect to each [A], [B], [C], and [D]. A + B = C + D with K1 for the forward reaction and K2 for the reverse reaction. Use the following data: For T=300K we have Keq= 9*10^-3 and K1=21.3 M^-1 sec^-1 For T=350K we have Keq= 1.6*10^-2 and K1= 3,696 M^-1 sec^-1 A) Find the activation energies for the forward and backward reaction (Eaf and Eab) and the pre-expontential...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT