“public class Helper {

public static String computeCWGrade(double score) {
String grade = “F”;
//TODO: Compute grade based on the score
return grade;
}

public static String computeRGrade(double score) {
String grade = “F”;
//TODO: Compute grade based on the score
return grade;
}
}
import java.util.ArrayList;

import java.util.;
import java.io.;

public class ResultProcessSystem {

//Constant for file name - do not change.
private final static String STUDENTS_DATA_FILE_NAME = “students.csv”;
private final static String UNITS_RESULT_DATA_FILE_NAME = “units_result.csv”;
private final static String RESULTS_RELEASE__OUTPUT_FILENAME = “results_release.csv”;
private final static String UNMATCH_UNITS_RESULT_FILENAME = “unmatch_units_result.csv”;

//One ArrayList to store both Coursework and Research Student and
//one Arraylist to store both Unit
//make use of Polymorphism!
private static ArrayList<Student> students;
private static ArrayList<Unit> units;

public static void run() {
students = new ArrayList<Student>();
units = new ArrayList<Unit>();
readInStudentsDataFromCSVFile();
readInStudentsUnitResultFromCSVFile();
matchUnitToStudent();
sortStudentsArrayListByStudentID();
printStudentArrayListToResultReleaseCSV();
printUnitsWithNoStudentsMatchToCSV();
}

private static void readInStudentsDataFromCSVFile() {

try {
Scanner file = new Scanner(new File(STUDENTS_DATA_FILE_NAME ));
while(file.hasNextLine()) {
//TODO: convert each record to a student object
//add student object to ArrayList students
file.nextLine();
}

}catch(FileNotFoundException ex) {
System.out.println(“Student data file not found”);
}
}

private static void readInStudentsUnitResultFromCSVFile() {
try {
Scanner file = new Scanner(new File(UNITS_RESULT_DATA_FILE_NAME));
while(file.hasNextLine()) {
//TODO: convert each record to either a Unit_Coursework
//or Unit_Research object and add it to ArrayList units.
file.nextLine();
}

}catch(FileNotFoundException ex) {
System.out.println(UNITS_RESULT_DATA_FILE_NAME+” file not found");
}
}

private static void matchUnitToStudent() {
//TODO: look for each student object unit results in units ArrayList
//assign the unit into the student object
//remove the assigned unit from units ArrayList
}

private static void sortStudentsArrayListByStudentID() {
//TODO: sort the ArrayList students by Student ID
}

private static void printStudentArrayListToResultReleaseCSV() {

try {
PrintWriter pw = new PrintWriter(RESULTS_RELEASE__OUTPUT_FILENAME);
//TODO: print result_release.csv
pw.close();

}catch(FileNotFoundException ex) {
System.out.println(“Unable to open “+RESULTS_RELEASE__OUTPUT_FILENAME);
}
}

private static void printUnitsWithNoStudentsMatchToCSV() {
try {
PrintWriter pw = new PrintWriter(UNMATCH_UNITS_RESULT_FILENAME);
//TODO: print unmatch_units_result.csv
pw.close();

}catch(FileNotFoundException ex) {
System.out.println(“Unable to open “+UNMATCH_UNITS_RESULT_FILENAME);
}
}

public static String getStudentsDataFileName() {
return STUDENTS_DATA_FILE_NAME;
}

public static String getUnitsResultDataFileName() {
return UNITS_RESULT_DATA_FILE_NAME;
}

public static String getResultsReleaseOutputFilename() {
return RESULTS_RELEASE__OUTPUT_FILENAME;
}

public static String getUnmatchUnitsResultFilename() {
return UNMATCH_UNITS_RESULT_FILENAME;
}

public static void main(String[] args) {
run();
}
}
public class ResultRelease {
private String studentID;
private String result;

public ResultRelease(String studentID, String result) {
this.studentID = studentID;
this.result = result;
}

public boolean equals(String studentID, String result) {
return this.studentID.equals(studentID) && this.result.equals(result);
}

public boolean equals(String studentID) {
return this.studentID.equals(studentID);
}

public String getStudentID() {
return studentID;
}

public boolean studentIDMoreThan(ResultRelease result) {
int n = this.studentID.compareTo(result.getStudentID());
if (n > 0) {
return true;
} else {
return false;
}
}
}
import java.util.;
import java.io.;

public class RPSTest {

private static ArrayList<ResultRelease> results;
private static ArrayList<Unit> unmatchUnits;
private static ResultProcessSystem RPS;

public static void main(String[] args) {
generateDataFiles();
deleteRPSGenerateFiles();

//execute ResultProcessSystem
RPS.run();

//read in result release data
readResultRelease();

//check if sort by student ID
try {
assert checkIfSortByStudentID() == true;
System.out.println(“Sort by Student ID test passed”);
}catch(AssertionError e) {
System.out.println(“Sort by Student ID test failed”);
}
//check if student result data is correct
try {
assert checkResultReleaseIsCorrect() == true;
System.out.println(“Result Release test passed”);
}catch(AssertionError e) {
System.out.println(“Result Release test failed”);
}

//check if unmatch unit is correct
readUnmatchUnits();

try {
assert checkUnmatchUnitIsCorrect() == true;
System.out.println(“Unmatch units test passed”);
}catch(AssertionError e) {
System.out.println(“Unmatch units test failed”);
}

}

private static boolean checkUnmatchUnitIsCorrect() {

//expected results
String u1 = “C444,CSIT511,55.0,45.0,48.0”;
String u2 = “R666,55.0,45.0”;

String[] uDatas = {u1,u2};

boolean result = true;
for(String s : uDatas) {
String[] data = s.split(”,”);
String id = data[0];
Unit unit = getUnmatchUnitByStudentID(id);
if(unit==null) {
result=false;
break;
}
if(!unit.getCSVString().equals(s)) {
result=false;
break;
}
}
return result;
}

private static Unit getUnmatchUnitByStudentID(String id) {
Unit toReturn = null;
for(Unit unit:unmatchUnits) {
if(unit.equals(id)) {
toReturn = unit;
break;
}
}
return toReturn;
}

private static void readUnmatchUnits() {
unmatchUnits = new ArrayList<Unit>();
try {
Scanner file = new Scanner(new File(RPS.getUnmatchUnitsResultFilename()));

while(file.hasNextLine()) {
String line = file.nextLine();
String[] data = line.split(”,”);
String id = data[0];

Unit unit = null;
if(id.startsWith(“C”)) {
String code = data[1];
double a1 = Double.parseDouble(data[2]);
double a2 = Double.parseDouble(data[3]);
double exam = Double.parseDouble(data[4]);
unit = new Unit_Coursework(id,code,a1,a2,exam);
}else if(id.startsWith(“R”)) {
double proposal = Double.parseDouble(data[1]);
double finalDissertation = Double.parseDouble(data[2]);
unit = new Unit_Research(id,proposal,finalDissertation);
}
unmatchUnits.add(unit);
}

}catch(FileNotFoundException ex) {
System.out.println(RPS.getUnmatchUnitsResultFilename()+" unable to open");
}
}

private static boolean checkResultReleaseIsCorrect() {
//expected results
String rr1 = “C111,HD”;
String rr2 = “C222,P”;
String rr3 = “C333,C”;
String rr4 = “C555,No unit attempt”;
String rr5 = “R111,F”;
String rr6 = “R222,P”;
String rr7 = “R333,P”;
String rr8 = “R444,Research incomplete”;

String[] rrDatas = {rr1,rr2,rr3,rr4,rr5,rr6,rr7,rr8};
boolean result = true;

for(String s : rrDatas) {
String[] data = s.split(“,”);
String id = data[0];
String r = data[1];
ResultRelease rr = getResultReleaseByStudentID(id);
if(rr==null || !rr.equals(id,r)) {
result = false;
break;
}
}
return result;
}


private static ResultRelease getResultReleaseByStudentID(String id) {
ResultRelease toReturn = null;
for(ResultRelease result: results) {
if(result.equals(id)) {
toReturn = result;
break;
}
}
return toReturn;
}

private static void readResultRelease() {
results = new ArrayList<ResultRelease>();
try {
Scanner file = new Scanner(new File(RPS.getResultsReleaseOutputFilename()));

while(file.hasNextLine()) {
String line = file.nextLine();
String[] data = line.split(“,”);
String studentID = data[0];
String result = data[1];
ResultRelease r = new ResultRelease(studentID,result);
results.add®;
}

}catch(FileNotFoundException ex) {
System.out.println(RPS.getResultsReleaseOutputFilename()+" unable to open");
}
}

private static boolean checkIfSortByStudentID() {
boolean sorted = true;
String[] data = {“C111”,“C222”,“C333”,“C555”,“R111”,“R222”,“R333”,“R444”};
if(results.size()==0) {
sorted = false;
}
for(int i=0;i<results.size();i++) {
if(!results.get(i).equals(data[i])) {
sorted = false;
break;
}
}
return sorted;
}


private static void deleteRPSGenerateFiles() {
File resultReleaseFile = new File(RPS.getResultsReleaseOutputFilename());
resultReleaseFile.delete();

File unmatchUnitsResult = new File(RPS.getUnmatchUnitsResultFilename());
unmatchUnitsResult.delete();
}

private static void generateDataFiles() {
//test data
String d1 = “C,Peter,Jordon,C222”;
String d2 = “C,John,Smith,C111”;
String d3 = “C,Bob,Church,C555”;
String d4 = “C,David,Jackson,C333”;
String d5 = “R,Gary,Kenny,R333”;
String d6 = “R,Eric,Trump,R222”;
String d7 = “R,Bob,Johnson,R111”;
String d8 = “R,Donald,Ray,R444”;

String[] sDatas = {d1,d2,d3,d4,d5,d6,d7,d8};

try {
PrintWriter pw = new PrintWriter(RPS.getStudentsDataFileName());
for(String s: sDatas) {
pw.println(s);
}
pw.close();
}catch(FileNotFoundException ex) {
System.out.println(RPS.getStudentsDataFileName()+" unable to open");
}

//test data
String r1 = “R222,85.0,72.0”;
String r2 = “C111,CSIT454,89.0,88.0,86.5”;
String r3 = “C333,CSIT511,75.5,72.0,58.5”;
String r4 = “R111,40.0,47.5”;
String r5 = “C222,CSIT454,76.0,56.5,65.0”;
String r6 = “R333,80.5,70.0”;
String r7 = “C444,CSIT511,55.0,45.0,48.0”;
String r8 = “R666,55.0,45.0”;
String[] rDatas = {r1,r2,r3,r4,r5,r6,r7,r8};

try {
PrintWriter pw = new PrintWriter(RPS.getUnitsResultDataFileName());
for(String s: rDatas) {
pw.println(s);
}
pw.close();
}catch(FileNotFoundException ex) {
System.out.println(RPS.getUnitsResultDataFileName()+" unable to open");
}
}
}
public class Student_Coursework extends Student{

private Unit_Coursework unit;

public Student_Coursework(String firstName, String lastName, String id) {
super(firstName, lastName, id,“C”);
}

public String getFinalGrade(){
//TODO: return the student final grade
String finalGrade = “NIL”;
return finalGrade;
}

public void setUnit(Unit unit) {
this.unit = (Unit_Coursework)unit;
}

public String getCSVString() {
return this.getId()+“,”+this.getFinalGrade();
}

}
public class Student_Research extends Student{

private Unit_Research unit;

public Student_Research(String firstName, String lastName, String id) {
super(firstName, lastName, id, “R”);
}

public String getFinalGrade(){
//TODO: return the student final grade
String finalGrade = “NIL”;
return finalGrade;
}

public void setUnit(Unit unit) {
this.unit = (Unit_Research)unit;
}

public String getCSVString() {
return this.getId()+“,”+this.getFinalGrade();
}
}
abstract public class Student {

private String firstName;
private String lastName;
private String id;
private String enrolmentType;

public Student(String firstName, String lastName, String id,String enrolmentType) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.enrolmentType = enrolmentType;
}

public String getEnrolmentType() {
return this.enrolmentType;
}

public String getFirstName() {
return this.firstName;
}

public String getLastName() {
return this.lastName;
}

public String getId() {
return this.id;
}

public boolean equals(String id){
return this.id.equals(id);
}

public boolean equals(Student student){
return this.id.equals(student.getId());
}

public boolean studentIDMoreThan(Student student){
int n = this.id.compareTo(student.getId());
if(n>0) {
return true;
}else {
return false;
}
}

public String toString() {
return this.id;
}

abstract public String getFinalGrade();

abstract public void setUnit(Unit unit);

abstract public String getCSVString();
}
public class Unit_Coursework extends Unit{

private String unitCode;
private double a1;
private double a2;
private double exam;

public Unit_Coursework(String studentID, String unitCode, double a1, double a2, double exam) {
super(studentID,“CW”);
this.unitCode = unitCode;
this.a1 = a1;
this.a2 = a2;
this.exam = exam;
}

public double getOverallMarks(){
//TODO: calculate coursework overall marks;
return 0;
}

public String getFinalGrade(){
return Helper.computeCWGrade(getOverallMarks());
}

public String getCSVString() {
//TODO: return a string in the following format
//studentID,unitCode,a1,a2,exam
return “studentID,unitCode,a1,a2,exam”;
}
}
public class Unit_Research extends Unit{

private double proposal;
private double finalDissertation;

public Unit_Research(String studentID, double proposal, double finalDissertation) {
super(studentID,“R”);
this.proposal = proposal;
this.finalDissertation = finalDissertation;
}

public double getOverallMarks(){
//TODO: calculate research overall marks;
return 0;
}

public String getFinalGrade(){
return Helper.computeCWGrade(getOverallMarks());
}

public String getCSVString() {
//TODO: return a string in the following format
//studentID,proposal,finalDissertation
return “studentID,proposal,finalDissertation”;
}

}
abstract public class Unit {

private String unitType;
private String studentID;

public Unit(String studentID, String unitType) {
this.studentID = studentID;
this.unitType = unitType;
}

public String getStudentID() {
return this.studentID;
}

public boolean equals(String id) {
return this.studentID.equals(id);
}

abstract double getOverallMarks();

abstract String getFinalGrade();

abstract String getCSVString();
}
"
“The UoWSIM graduate school offers coursework and research program.
Courswork:
The coursework student takes one Unit in each term and the assessment components are:
Assignment 1 (20%)
Assignment 2 (30%)
Exam (50%)
Each assessment is upon 100 marks.
The student will be awarded a grade based on the following:
Grade
Score
HD (High Distinction)
(85%-100%)
D (Distinction)
(75%-84%)
C (Credit)
(65%-74%)
P (Pass)
(50%-64%)
F (Fail)
(0%-49%)
Research:
The coursework student takes one Unit in each term and the assessment components are:

Proposal (30%)

Final Dissertation (70%)
Each assessment is upon 100 marks.
The student will be awarded a grade based on the following:
Grade
Score
P (Pass)
(50%-100%)
F (Fail)
(0%-49%)
The Result Processing System (RPS) is used to process the student results.
RPS will read in students and units result from two csv files: students.csv and units_result.csv.
students.csv
o This file stores the student’s information.
units_result.csv
o This file stores the student’s unit result.
(See appendix for sample students.csv and units_result.csv)
RPS will generate two csv files: result_releases.csv and unmatch_units_result.csv.
result_releases.csv
o This file contains the student id and grade for each student.
o If the student unit result is not found, it will be reported as either “No unit attempt” or “Research incomplete”.
unmatch_units_result.csv
o Some unit result in units_result.csv cannot be matched to any student id in students.csv. Such unmatched units will be stored in this file.
(See appendix for sample result_releases.csv and unmatch_units_result.csv)
2
Task:
A partial completed Result Processing System (RPS) has been given.
Look through the codes and complete the missing codes.
Hints are given in the codes as comments.
Assumption:
All csv file data formats are correct.
All csv file data scores are correct.
Automated Testing
RPSTest.java is the testing program for the Result Processing System.
You need to enable Assertion to enable the testing.
You need to follow strictly to the given csv file format else the Automate testing will fail.
You should get the following result from RPSTest.java if you have completed the lab.
Sort by Student ID test passed
Result Release test passed
Unmatch units test passed”
write the missing TODO codes for the helper, student_coursework, student_research, unit_coursework, unit_research class in this ide java program.