Write a program that will deal with the following scenario. A lecturer gives a true/false weekly text to class of students. The lecturer writes the correct answers to a file called answers.txt. (It is not necessary to store previous answers). As each of the students takes the test the answers for the 10 questions are written to a file called studentAnswers.txt preceded by the student number. (Again there is no need to store the precious answers).

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 PreviewSolution 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.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(;
ArrayList<StudentScore> studentResults = new ArrayList<StudentScore>();
File outAnswers = new File(studentFile), outScores = new File(scoresFile);
FileWriter fwAnswers, fwScores;
try {
fwAnswers = new FileWriter(outAnswers.getAbsoluteFile());
fwScores = new FileWriter(outScores.getAbsoluteFile());
} catch (IOException e) {
System.out.println("File could not be created, exiting");

BufferedWriter bwAnswers = new BufferedWriter(fwAnswers);
BufferedWriter bwScores = new BufferedWriter(fwScores);

$30.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats