Other 2007 FR Questions FR other years Be Prepared Home
A-3
Part (a)
  /** @param key the list of correct answers, represented as strings of length one
   *         Precondition: key.size() is equal to the number of answers in this answer sheet
   *  @return this student's test score
   */
  public double getScore(ArrayList<String> key)
  {
    double score = 0.0;

    for (int i = 0; i < answers.size(); i++)
    {
      if (answers.get(i).equals(key.get(i)))
        score += 1.00;
      else if (!answers.get(i).equals("?"))
        score -= 0.25;
    }

    return score;
  }

Part (b)
  /** 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(ArrayList<String> key)
  {
    StudentAnswerSheet best = sheets.get(0);
    for (StudentAnswerSheet s : sheets)
      if (s.getScore(key) > best.getScore(key))
        best = s;
    return best.getName();
  } 1
Notes:
  1. Also possible:
        ...
        StudentAnswerSheet best = null;
        for (StudentAnswerSheet s : sheets)
          if (best == null || s.getScore(key) > best.getScore(key))
            ...
        ...

Other 2007 FR Questions | Back to Contents

Copyright © 2007 by Skylight Publishing
support@skylit.com