2007 Student Answer Sheet

<< 2007SelfDivisor | APQuestionsTrailIndex | 2007GameState >>

Question from College Board

StudentAnswerSheet

import java.util.ArrayList;

public class StudentAnswerSheet
{
  private ArrayList<String> answers;  // the list of the student's answers
  private String name;

  public StudentAnswerSheet(String nm, ArrayList<String> ans)
  {
    name = nm;
    answers = new ArrayList<String>();
    for (String a : ans)
      answers.add(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)
  {
     //part a here



  }

  // accessor (or get) methods
  public String getName()
  {
    return name;
  }
  public ArrayList<String> getAnswers()
  {
    return answers;
  }
}

TestResults

import java.util.ArrayList;

public class TestResults
{
  private ArrayList<StudentAnswerSheet> sheets;

  public TestResults(ArrayList<StudentAnswerSheet> shs)
  {
    sheets = new ArrayList<StudentAnswerSheet>();
    for (StudentAnswerSheet s : shs)
      sheets.add(s);
  }



  /** 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)
  {
    //part b here
  }


}

TestScoreDriver

import java.util.ArrayList;
import java.util.Arrays;

public class TestScoreDriver
{
  public static void main(String[] args)
  {
    ArrayList<String> key = new ArrayList<String>(Arrays.asList(
              new String[] {"A", "C", "D", "E", "B", "C", "E", "B", "B", "C"}));

    ArrayList<String> answers1 = new ArrayList<String>(Arrays.asList(
              new String[] {"A", "B", "D", "E", "A", "C", "?", "B", "D", "C"}));

    ArrayList<String> answers2 = new ArrayList<String>(Arrays.asList(
              new String[] {"A", "?", "D", "E", "A", "C", "?", "B", "D", "C"}));

    ArrayList<String> answers3 = new ArrayList<String>(Arrays.asList(
              new String[] {"A", "?", "D", "E", "A", "C", "E", "B", "D", "C"}));

    ArrayList<String> answers4 = new ArrayList<String>(Arrays.asList(
              new String[] {"A", "C", "D", "E", "A", "C", "E", "B", "D", "C"}));



    StudentAnswerSheet alex=new StudentAnswerSheet("Alex", answers1);
    StudentAnswerSheet betty=new StudentAnswerSheet("Betty", answers2);
    System.out.println("The key is "+key);
    System.out.println("Alex chose "+alex.getAnswers());
    System.out.println("Alex's score is (should be 5.25):"+alex.getScore(key));
    ArrayList<StudentAnswerSheet> sheets = new ArrayList<StudentAnswerSheet>();
    sheets.add(alex);
    sheets.add(betty);
    sheets.add(new StudentAnswerSheet("Clive", answers3));
    sheets.add(new StudentAnswerSheet("Donna", answers4));



    for (StudentAnswerSheet s : sheets)
    {
      System.out.println(s.getName() + ": " + s.getScore(key));
    }
    TestResults results = new TestResults(sheets);
    System.out.println("Best is (should be Donna with a score of 7.5): " + results.highestScoringStudent(key));
  }
}