Ask Question
13 March, 01:39

In java write a program:A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output that name's phone number. Assume that the list will always contain less than 20 word pairs. Ex: If the input is:3 Joe 123-5432 Linda 983-4123 Frank 867-5309 Frankthe output is:867-5309Your program must define and call the following method. The return value of GetPhoneNumber is the phone number associated with the specific contact name. public static String GetPhoneNumber (String[] nameVec, String[] phoneNumberVec, String contactName, int arraySize) Hint: Use two arrays: One for the string names, and the other for the string phone numbers.

+5
Answers (1)
  1. 13 March, 01:47
    0
    import java. util. Scanner;

    public class ContactInformation

    {

    public static String GetPhoneNumber (String[] nameVec, String[] phoneNumberVec, String contactName, int arraySize)

    {

    for (int i=0; i
    {

    if (nameVec[i]. equals (contactName))

    return phoneNumberVec[i];

    }

    return "Contact doesn't exists!";

    }

    public static void main (String[] args)

    {

    int records;

    Scanner sc = new Scanner (System. in);

    System. out. print ("Enter the size of contact List : ");

    records=sc. nextInt ();

    String[] contactNameList=new String[records];

    String[] phoneNumberList=new String[records];

    String contactName;

    System. out. println ("Enter the contact name and phone number : ");

    for (int i=0; i
    {

    contactNameList[i]=sc. next ();

    phoneNumberList[i]=sc. next ();

    }

    System. out. println ("Enter the name of the contact to be searched : ");

    contactName=sc. next ();

    System. out. println (GetPhoneNumber (contactNameList, phoneNumberList, contactName, records));

    }

    }

    Explanation:

    In the following the function defined above for getting the contact

    number on the basis of contact number provided we are checking the contact name list if we are able to find the contact name and if we did we return the contact number on the same index from the contact number list

    which we found in the contact name list.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “In java write a program:A contact list is a place where you can store a specific contact with other associated information such as a phone ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers