Answer: import java.util.Scanner;
public class ContactList {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Read the number of word pairs in the list
int n = scnr.nextInt();
scnr.nextLine(); // Consume the newline character
// Read the word pairs and store them in two arrays
String[] names = new String[n];
String[] phoneNumbers = new String[n];
for (int i = 0; i < n; i++) {
String[] parts = scnr.nextLine().split(",");
names[i] = parts[0];
phoneNumbers[i] = parts[1];
}
// Read the name to look up
String name = scnr.nextLine();
// Call the getPhoneNumber method to look up the phone number
String phoneNumber = getPhoneNumber(names, phoneNumbers, name, n);
// Print the phone number, or "None" if the name is not found
if (phoneNumber != null) {
System.out.println(phoneNumber);
} else {
System.out.println("None");
}
}
public static String getPhoneNumber(String[] nameArr, String[] phoneNumberArr, String contactName, int arraySize) {
// Search for the name in the array and return the corresponding phone number
for (int i = 0; i < arraySize; i++) {
if (nameArr[i].equals(contactName)) {
return phoneNumberArr[i];
}
}
// If the name is not found, return null
return null;
}
}
Explanation: The program inputs the number of word sets, stores them in two clusters (names and phoneNumbers), and looks up a title by calling the getPhoneNumber strategy to return the comparing phone number. Prints phone number or "None" in the event that title not found. getPhoneNumber strategy takes nameArr, phoneNumberArr, contactName, and arraySize as contentions. The strategy looks for a title and returns the phone number in case found, something else invalid.