Problem

A more scalable solution is to make anarray of an obeject that stores the name and corresp...

A more scalable solution is to make anarray of an obeject that stores the name and corresponding phonenumbet.Modify the program to use a single array of an object. Theoutput should remain the same.

The following code creates a small phone book. An array is used to store a list of names and another array is used to store the phone numbers that go with each name. For example, Michael Myers’ phone number is 333-8000 and Ash Williams’ phone number is 333-2323.

Write the method lookupName so the code properly looks up and returns the phone number for the input target name. lookupName should return a blank string if the name is not in the phone book.

Scanner kbd = new Scanner(System.in);String[] names = {"Michael Myers", "Ash Williams","Jack Torrance", "Freddy Krueger"};String[] phoneNumbers = {"333-8000","333-2323","333-6150","339-7970"};System.out.println(“Enter name to look up.”);String targetName = kbd.nextLine();String targetPhone = lookupName(targetName, names,phoneNumbers);System.out.println(“The phone number is " + targetPhone);

The object-based approach is more scalable than this approach, which requires a separate array to be managed for every property of the phone contact.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT