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

highlyPaidWomen

Language/Type: Java Guava BiMap collections
Author: Marty Stepp (on 2013/02/23)

Write a method named highlyPaidWomen that returns a set of names of women who earn more money than their husbands. The method accepts two parameters: 1) a marriage BiMap from strings to strings, where each key/value pair represents the name of a husband and wife; and 2) a salary Map from strings to real numbers, where each key/value pair represents a person's name and that person's salary at his/her job. Your method should examine these collections and return a Set of names of all women who are employed and earn a salary that is strictly greater than than their husband's salary. The set should be in sorted alphabetical order. Note that not every person has a job; if not, they will be absent from the salary map. If the wife is employed and the husband is not, by default she makes more money than her husband and should be included in the set.

For example, suppose your method is passed the following marriage bi-map and salary map:

{Fred=Wilma, Homer=Marge, Peter=Lois, Tarzan=Jane, Simba=Nala, Ricky=Lucy, ...}
{Lois=29.0, Fred=44.0, Nala=97.0, Marge=8.0, Peter=13.0, Lucy=11.0, Homer=5.0, Ricky=22.0}

Your method would return the set [Lois, Marge, Nala] because Lois makes 29.0 to Peter's 13.0, Marge makes 8.0 to Homer's 5.0, and Nala makes 97.0 while Simba is unemployed. Wilma and Jane are not in the set because they are unemployed, and Lucy is not in the set because she makes less salary than Ricky.

Your code should run in O(N log N) time where N is the number of key/value pairs in the salary map. For the purposes of this problem, we will assume that the marriage bi-map is likely to be much larger than the salary map, therefore it is inefficient and inappropriate to loop over every single key/value pair in the bi-map. You may assume that every name in the salary map appears in the bi-map as a key or value.

You may assume that none of the collections passed, nor any of the keys/values in them, are null. Do not construct any auxiliary collections other than the set to return. You should not modify any of the collections passed in.

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.