Question
Sample File: studentAnswers.txt
L00001211 t t t x t x t f f F
L00001232 f x t t t t x x f f
L00001243 t t f f t t t f f f
L00001254 f t t x t x x t f f
When the deadline passes the lecturer will be able to correct the assignments using the program. Your program should read the correct answers from the file ( answes.txt ), mark the tests for each student as stored in studentAnswers.txt. When they are marked the scores should be appended to a file, scores.txt, preceded by a time stamp and followed by a line showing the total number of students took the weekly test and the average score. (See below).
Sample file: Scores.txt
Wed Mar 12 18:30:26 GMT 2014
L00001211 4
L00001232 10
L00001243 8
L00001254 8
NO of Students 4; average 7.5;
Wed Mar 5 12:25:20 GMT 2014
L00001211 4
L00001232 10
L00001243 8
L00001254 8
NO of Students 4; average 7.5;
Your program should simulate the student taking the test i.e should be prompted for a student NO and 10 answers.
Marking: 2 marks awarded for each correct answer and 1 is deducted for each incorrect answer. 0 is awarded for a skipped question. Each student must answer 10 questions, t for true, f for false and x if unknown.
NB: code should include appropriate exception handling and validation/testing. A short report on testing required.
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.io.BufferedWriter;import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class TestGrader {
public static void main(String[] args) throws IOException
{
String answerFile = "answers.txt", studentFile = "studentAnswers.txt", scoresFile = "scores.txt";
Scanner inputAnswer, inputStudent, sysin = new Scanner(System.in);
ArrayList<StudentScore> studentResults = new ArrayList<StudentScore>();
File outAnswers = new File(studentFile), outScores = new File(scoresFile);
FileWriter fwAnswers, fwScores;
try {
outAnswers.createNewFile();
outScores.createNewFile();
fwAnswers = new FileWriter(outAnswers.getAbsoluteFile());
fwScores = new FileWriter(outScores.getAbsoluteFile());
} catch (IOException e) {
System.out.println("File could not be created, exiting");
return;
}
BufferedWriter bwAnswers = new BufferedWriter(fwAnswers);
BufferedWriter bwScores = new BufferedWriter(fwScores);
while(true)
{...