Consider a system for processing student test scores. The StudentAnswerSheet class is given and will be used as part of this system and contains a student's name and the student's answers for a multiple-choice test. Note the class attribute (key) and method (setKey) for the loading and storing the answer key. The answers are represented as "char" with an omitted answer being represented by the question mark '?'. These answers are stored in an array in which the position of the answer corresponds to the question number on the test (question numbers start at zero). A student's score on the test is computed by comparing the student's answers with the corresponding answers in the answer key for the test. One point is awarded for each correct answer and 1/4 point is deducted for each incorrect answer. Omitted answers do not change the student's score.
Write a class GradeStudents with a "main" method only that will read, using Scanner, a filename from the user (assumed to exist and in the correct format). Then read the comma-delimited input file containing the answer key in the first row and student names/answers in other rows, one per line.
First read and load the key. Then read, grade and output each student. Also determine the highest scoring student. If ties for highest scoring save all their names. You do not know how many questions are on the test until you read the first line of the file, which is always the key.
Given class:
public class StudentAnswerSheet {
private String name;
private char [] answers;
private static final char BLANK='?';
private static final String DEFAULT_NAME="Noname";
private static final double CORRECT_POINTS=1., BLANK_POINTS=0., WRONG_POINTS=-.25;
private static char [] key;
public static void setKey(char [] answerKey) {
if (answerKey==null || answerKey.length==0) {
key=new char[] {'?'};
}
else {
key=new char[answerKey.length];
for (int i=0;i key[i]=answerKey[i];
}
}
}
public StudentAnswerSheet (String n, char [] a) {
if (n==null) {
name=DEFAULT_NAME;
}
else {
name=n;
}
if (a!=null && a.length>0) {
answers=new char[a.length];
for (int i=0;i answers[i]=a[i];
}
}
else {
answers = new char[] {'?'};
}
}
public String getName() { return name; }
public double getScore () {
double total=0;
if (key!=null && key.length == answers.length) {
for (int i=0;i if (answers[i]==BLANK) {
total+=BLANK_POINTS;
}
else if (answers[i]==key[i]) {
total+=CORRECT_POINTS;
}
else {
total+=WRONG_POINTS;
}
}
}
else {
total=Double.NEGATIVE_INFINITY;
}
return total;
}
public String toString () {
String temp = name;
for (int i=0; i temp = temp + ' ' + answers[i];
}
return temp;
}
}
SAMPLE INPUT FILES:
answers1.txt
KEY,e,e,b,b,e,b,c,d,a,e
Matt,a,e,b,b,?,b,c,d,a,e
Cami,e,e,b,b,?,b,c,d,a,e
John,?,?,?,?,?,?,c,d,a,e
Mary,a,a,a,a,a,a,c,d,a,e
Fred,e,e,b,b,?,b,c,d,a,ea
answers2.txt
KEY,e,e,b,b,e,b,c,d,a,e,e,e,b,b,e,b,c,d,a,e
Matt,a,e,b,b,?,b,c,d,a,e,a,a,a,a,a,a,c,d,a,e
Cami,e,e,b,b,?,b,c,d,a,e,?,?,?,?,?,?,c,d,a,e
John,?,?,?,?,?,?,c,d,a,e,a,a,a,a,a,a,c,d,a,e
Mary,a,a,a,a,a,a,c,d,a,e,a,a,a,a,a,a,c,d,a,e
Fred,e,e,b,b,?,b,c,d,a,e,e,e,b,b,?,b,c,d,a,e

Respuesta :

To write a class GradeStudents with a "main" method only that will read, using Scanner, a filename from the user (assumed to exist and in the correct format) check the code given below.

What is a filename?

The title of a file and its extension are included in its filename. An entire file name is, for instance, "readme.txt."

Additionally, only the first part of a file may be described in the file name. A file with the name "readme" and the file name extension ".txt" is an example.

↓↓//CODE//↓↓

package code;

 public class TestResults

{

    private StudentAnswerSheet[] students;

    private int count = 0;

     private static final int DEFAULT_SIZE = 10;

     public TestResults(int size)

{

        if (size > 0) {

            students = new StudentAnswerSheet[size];

        }

        else {

            students = new StudentAnswerSheet[DEFAULT_SIZE];

        }

        count = 0;

    }

     public boolean addStudentAnswerSheet(StudentAnswerSheet x) {

        boolean inserted = false;

         if (x != null && count < students.length) {

            students[count] = x;

            count++;

            inserted = true;

        }

         return inserted;

    }

     public String highestScoringStudent(char[] answerKey) {

                 double maxScore = Double.MIN_VALUE;

        double tempScore;

                 // Finding maximum score

        for (StudentAnswerSheet sheet : students) {

            tempScore = sheet.getScore(answerKey);

                             if (tempScore > maxScore) {

                maxScore = tempScore;

            }

        }

                 // building highest achievers list

        StringBuilder res = new StringBuilder();

                 for (StudentAnswerSheet sheet : students) {

            if (sheet.getScore(answerKey) == maxScore) {

                res.append(sheet.getName()).append(" ");

            }

        }

                 // returning list string

        return res.toString().strip();

    }

}

Learn more about filename

https://brainly.com/question/28578338

#SPJ4