Question

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 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)
{...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Java Project For Consulting Company
Homework Solution
$50.00
Java
Programming
Computer Science
Consulting Company
Inventory
Interfaces
Products
Lookup
Classes
Libraries
Queries
Finance
Employees
Management
OOP
Function
Methods
Loops
Conditions
Roman Numerals in Java
Homework Solution
$35.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Roman Numerals
Integers
Messages
Input
Output
Arabic Format
Strings
Integers
Nested Statements in Java
Homework Solution
$15.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Nested Statements
For Statement
While Statement
Java Program With Lists & Integers
Homework Solution
$40.00
Java
Programming
Codes
Algorithms
Linked Lists
File Management
Data Structures
Libraries
Scanner
Zero Sum Subset
Input
Output
Statements
Variables
Positive Integers
Negative Integers
Binary Mask
Pseudo-Codes
Get help from a qualified tutor
Live Chats