logo Practice-It logo

commonCustomers

Language/Type: Java Sets and Maps Collections
Author: Roy McElmurry

Write a method commonCustomers that accepts two parameters, a Map from customer names (strings) to their television account numbers (integers) and a Map from customer names (strings) to their internet account numbers (integers), and returns a Map from customer names (strings) to their account number (integers) for each customer that has both a television account and a internet account. Assume that each customer with both types of accounts has the same account number for both accounts. For example, if a map tvAccounts contains these pairs:

{Marty=84321, David=23435, Stef=13266, Kim=62692, Lisa=25262}

and a map internetAccounts contains these pairs:

{Rob=93754, David=23435, Angela=42622, Kim=62692, Jason=36212}

The call of commonCustomers(tvAccounts, internetAccounts) should return a map containing these pairs:

{David=23435, Kim=62692}

because David and Kim have both television accounts and internet accounts. You may assume that the maps passed are not null and that no key or value in either is null. If either of the maps are empty or contain no common customers, your method should return an empty Map. You may create one collection of your choice as auxiliary storage to solve this problem.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.