Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that has two parallel arrays of String objects. One of the array

ID: 3621221 • Letter: W

Question

Write a program that has two parallel arrays of String objects. One of the arrays should hold people's names and the other should hold their phone numbers. Here are sample contents of both arrays.

name ArraySampleContents phone ArraySampleContents
"Harrison, Rose" "555-2234"
"James, Jean" "555-9098"
"Smith, William" "555-1785"
"Smith, Brad" "555-9224"

The program should ask the user to enter a name or the first few characters of a name to search for in the array. The program should display all of the names that match the user's input and their corresponding phone numbers. For example, if the user "Smith," the program should display the following names and phone numbers from the list:

Smith, William: 555-1785
Smith, Brad: 555-9224

Explanation / Answer

please rate - thanks

import java.util.*;
public class PhoneList
{public static void main(String [] args)
     {String name[]={"Harrison, Rose","James, Jean","Smith, William","Smith, Brad" };
    String phone[]={"555-2234",      "555-9098",    "555-1785",     "555-9224"};   
    String n;
    int i;
    boolean found=false;
    Scanner in=new Scanner(System.in);
    System.out.print("enter a name or the first few characters of a name: ");
    n=in.next();
    for(i=0;i<name.length;i++)
         {if(name[i].indexOf(n)>=0)
             {System.out.println(name[i]+": "+phone[i]);
            found=true;
            }
        }
        if(!found)
           System.out.println(n+" not found in the phone list");
   
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote