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

Design a program that has two parallel arrays: a String array named people that

ID: 3858817 • Letter: D

Question

Design a program that has two parallel arrays: a String array named people that is initialized with the names of seven of your friends, and a String array named phone-Numbers that is initialized with your friends' phone numbers. The program should allow the user to enter a person's name (or part of a person's name). It should then search for that person in the people array. If the person is found, it should get that person's phone number from the phoneNumbers array and display it. If the person is not found in the people array, the program should display a message indicating so.

Explanation / Answer

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