You have been asked to write a program to grade the results of a true-false quiz
ID: 440533 • Letter: Y
Question
You have been asked to write a program to grade the results of a true-false quiz and display the results in tabular form. The quiz consists of 10 questions. The data file for this problem consists of 1 set of correct responses (answerkey) on line one and succeeding lines containing a four digit student identification number followed by that student's 10 responses. (The numberof students taking the quiz in currently unknown.)
The data file is in the form :
TFFTFTTFTT
0461 TTFTTFTFTT
3218 TFFTTTTTFT
.....................
....................
Your program should read the key and store it in a one dimensional array. It should then read and process each succeeding line, storing the student identification numbers in a one dimensional array and the grades in two separateone dimensional arrays- one for numeric grades and the for letter grades.
Numeric grades are converted to letter according to the following system : A(10), B(9), C(8-7), D (6-5), F(4-0).
Program output should include the following :
1. Each Student's four digit identification number, their numeric grade and their letter grade.
2. A printed count of how many students took the quiz.
3. The numeric quiz average for the entire class.
4. A frequency count of the number of A's, B's, C's,D's and F's for the entire class.
Expected structures includeloops, parallel arrays, strings, methods and parameter passing
Here is the Text File:
Explanation / Answer
//import Packages
import java.util.*;
import java.io.*;
// Student Class
class Student {
String ID;
int numGrade;
char letterGrade;
char[] answers;
// student Constructor
public Student(String ID, int length) {
this.ID = ID;
numGrade = 0;
letterGrade = 'F';
answers = new char[length];
}
// return ID
public String getID() {
return this.ID;
}
// return Grade
public char getGrade() {
return letterGrade;
}
// set Grade
public void setGrade(char grade) {
this.letterGrade = grade;
}
// set num Grade
public void setNumGrade(int grade) {
this.numGrade = grade;
}
// get Number Grade
public int getNumGrade() {
return numGrade;
}
// AnswerKey Corresponding to a student
public void setAnswerKey(char[] answers) {
this.answers = answers;
}
public char[] getAnswerKey() {
return this.answers;
}
}
// grade class
class Grade {
int numStudents;
int studentCount;
double average;
int countA, countB, countC, countD, countF;
FileReader fin;
char answerKey[];
String ID;
ArrayList<Student> studList; // list containing each student record
String stAnswer;
String str, ansStr;
BufferedReader bufferedReader;
// read method reads and compute the results
public void read() {
try {
fin = new FileReader("Test.txt");
bufferedReader = new BufferedReader(fin);
countA = countB = countC = countD = countF = 0;
int count = 0;
average = 0;
boolean[] result;
studList = new ArrayList<Student>();
String b;
while ((b = bufferedReader.readLine()) != null) {
if (count == 0) {
answerKey = b.toCharArray();
} else {
ID = b.substring(0, 4);
System.out.print(ID + ":");
stAnswer = b.substring(5);
Student s = new Student(ID, stAnswer.length());
s.setAnswerKey(stAnswer.toCharArray());
result = new boolean[stAnswer.length()];
int resultCount;
resultCount = match(answerKey, s.getAnswerKey());
average += (double) resultCount;
char charGrade;
if (resultCount >= 0 && resultCount <= 4) {
charGrade = 'F';
countF++;
} else if (resultCount > 4 && resultCount <= 6) {
charGrade = 'D';
countD++;
} else if (resultCount > 6 && resultCount <= 8) {
charGrade = 'C';
countC++;
} else if (resultCount == 9) {
charGrade = 'B';
countB++;
} else {
charGrade = 'A';
countA++;
}
s.setGrade(charGrade);
s.setNumGrade(resultCount);
studList.add(s);
}
count++;
}
--count;
System.out.println("Student ID NUM_GRADES Letter_Grade");
for (Student s : studList) {
System.out.print(s.getID() + " " + s.getNumGrade() + " " + s.getGrade());
System.out.println();
}
System.out.println("Number of Student = " + count);
System.out.printf("Average = %.2f ", average / count);
System.out.println("Number of A Grages = " + countA);
System.out.println("Number of B Grades = " + countB);
System.out.println("Number of C Grades = " + countC);
System.out.println("Number of D Grades = " + countD);
System.out.println("Number of F Grades = " + countF);
} catch (Exception e) {
e.printStackTrace();
}
}
public int match(char[] one, char two[]) {
int count = 0;
for (int i = 0; i < one.length; i++) {
if (one[i] == two[i]) {
count++;
}
}
return count;
}
}
public class GradeTest {
public static void main(String args[]) {
Grade g = new Grade();
g.read();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.