Question: Write a program that has three parallel arrays of String objects. One of the arrays should hold last name, one should hold first name, and

Write a program that has three parallel arrays of String objects. One of the arrays should hold last name, one should hold first name, and the other should hold phone numbers. Here are example contents of both arrays:

The program should read contactList.txt and insert the appropriate data from the file into the respective elements of each array.

The program should then ask the user to enter a last name or the first few characters of a last name to search for in the array. The program should display all of the names that match the users input and their corresponding phone numbers.

contactList.txt has:

Harrison, Rose, 555-2234 James, Jean, 555-9098 Smith, William, 555-1785 Smith, Brad, 555-9224 

My code:

import java.io.*;

import java.util.Scanner;

public class Telemarketing {

public static void main (String[] args) throws IOException {

File file= new File ("contactList.txt");

if (!file.exists()) {

System.out.println("No file exists.");

System.exit(0);

}

Scanner inputFile=new Scanner(file);

String lnameArray[] = new String[4];

String fnameArray[] = new String[4];

String phoneArray[] = new String[4];

Scanner keyboard=new Scanner(System.in);

int x;

x=0;

while(inputFile.hasNextLine())

{

String splitArray[] = inputFile.nextLine().split(", ", 3);

lnameArray[x] = splitArray[0];

fnameArray[x]=splitArray[1];

phoneArray[x]=splitArray[2];

x++;

}

System.out.println("Enter first few characters of the surname in search: ");

String input = keyboard.nextLine();

for (int i = 0; i < lnameArray.length; i++)

{if(lnameArray[i].substring(0, input.length()).equals(input)) {

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!