This is a beta version of Practice-It. Give us feedback

logo Practice-It logo

recordGrade

Language/Type: Java Collections Sets and Maps
Author: Marty Stepp (on 2021/04/02)

Write a method called recordGrade that takes as parameters a map of student grades, a student id, a numerical grade, and a course, and that records the grade in the map. The student id is used as a key for the overall map with each id associated with a map of student grades. The map of student grades uses the course as a key and associates each course with a numerical grade (stored in an object of type Double). For example, suppose that a variable called grades stores a map with information for two students each with grades in two courses:

        {1212121={cse142=3.0, engl111=2.5}, 4444444={cse143=3.6, engl131=3.8}}

The following calls indicate a new grade for student 4444444 (3.2 in phys121) and a grade for a new student (3.5 in math126 for student 1234567).

        recordGrade(grades, "4444444", 3.2, "phys121");
        recordGrade(grades, "1234567", 3.5, "math126");

After the call, the grades map would store:

        {1212121={cse142=3.0, engl111=2.5}, 1234567={math126=3.5},
         4444444={cse143=3.6, engl131=3.8, phys121=3.2}}

Notice that the map now includes grade information for student 1234567 and a third grade for student 4444444. A student may take a course more than once, in which case you should store the highest grade the student has gotten for that course. For example, the call:

        recordGrade(grades, "1212121", 2.8, "engl111");

would change the map to:

        {1212121={cse142=3.0, engl111=2.8}, 1234567={math126=3.5},
         4444444={cse143=3.6, engl131=3.8, phys121=3.2}}

If the call instead had been with a grade of 2.4 in engl111, the map would have been unchanged because that grade is lower than the grade currently in the map. The overall map has keys that are ordered by student ID and each student's map of grades should be ordered by the course number.

Your method should construct a map for each student not already in the overall map and you may construct iterators, but you are not allowed to construct other structured objects (no string, set, list, etc.).

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.