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
11. First and Last Design a program that asks the user for a series of names...
11. First and Last Design a program that asks the user for a series of names (in no particular order). After the final person's name has been entered, the program should display the name that is first alphabetically and the name that is last alphabetically. For example, if the user enters the names Kristin, Joel, Adam, Beth, Zeb, and Chris, the program would display Adam and Zeb. #Sentinel value is DONE SENTINEL = "DONE" ls = [] prompt = "Enter...
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.
Write a tester program to test the mobile class defined below. Create the class named with...
Write a tester program to test the mobile class defined below. Create the class named with your id (for example: Id12345678) with the main method. Create two mobiles M1 and M2 using the first constructor. Print the characteristics of M1 and M2. Create one mobile M3 using the second constructor. Change the id and brand of the mobile M3. Print the id of M3. Your answer should include a screenshot of the output. Otherwise, you will be marked zero for...
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?
IN MY SQL: - Display each Author’s ID, first and last names and the total number...
IN MY SQL: - Display each Author’s ID, first and last names and the total number of pages for all of the Books they have written. - Display each Book genre as well as the number of Books written in that genre with the column header “Number Of Books” - Display the Author’s first and last name, as well as their ID, and the Book title and number of pages for all of the books they have written that have...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT