logo Practice-It logo


Language/Type: Java Collections Sets and Maps
Author: Marty Stepp

Write a method whoPassed that determines which students "passed" a course. The method accepts three parameters: A students map from students' names (strings) to their overall percentages (integers) in the course; a grades map from percentages (integers) to course grades out of 4.0 (real numbers); and a minGrade real number representing the minimum grade out of 4.0 required to pass. Your method should return a set containing the names of all students who earned at least the given minimum grade out of 4.0 (inclusive) For example, if your method is passed the following three parameters:

students = {Marty=76, Daniel=81, Alyssa=98, Kim=52, Lisa=87, Whitaker=43, Jeff=70, Sylvia=92}
grades   = {76=2.1, 81=2.6, 98=4.0, 52=0.0, 87=3.3, 43=0.0, 70=1.5, 92=3.7}
minGrade = 2.6

Then your method should return the following set of names, because Alyssa's percentage of 98 earns her a grade of 4.0 in the course, Daniel's 81 earns him a 2.6, Lisa's 87 earns her a 3.3, and Sylvia's 92 earns her a 3.7:

[Alyssa, Daniel, Lisa, Sylvia]

The names can be in any order in the set. If no students meet the desired minimum grade, return an empty set. You may assume that no parameter is null, that every student's percentage is between 0 and 100 inclusive, that the grades map contains a grade entry between 0.0 and 4.0 inclusive for every percentage earned by a student, and that the minGrade parameter is between 0.0 and 4.0 inclusive. For full credit your code must run in less than O(n2) time where n is the number of students and/or percentages.

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.