15.6. StudentAnswerSheet - Part B

Part b. Consider the following class that represents the test results of a group of students that took a multiple-choice test.

public class TestResults
{
    private List<StudentAnswerSheet> sheets;

    /**
     * Precondition: sheets.size() > 0; all answer sheets in sheets have the same
     * number of answers
     *
     * @param key the list of correct answers represented as strings of length one
     *     Precondition: key.size() is equal to the number of answers in each of
     *     the answer sheets in sheets
     * @return the name of the student with the highest score
     */
    public String highestScoringStudent(List<String> key)
    {
        /* to be implemented in part (b) */
    }

    // There may be fields, constructors, and methods that are not shown.
}

Write the TestResults method highestScoringStudent, which returns the name of the student who received the highest score on the test represented by the parameter key. If there is more than one student with the highest score, the name of any one of these highest-scoring students may be returned. You may assume that the size of each answer sheet represented in sheets is equal to the size of key.

15.6.1. Try and Solve It

Complete method highestScoringStudent below.

The code below has a main method for testing the highestScoringStudent method.

Complete method highestScoringStudent below.

Before you keep reading...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

You have attempted 1 of 2 activities on this page