Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

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.