package project02; import java.util.ArrayList; import java.util.Arrays; // required for auto grading /** * midterm, homework, final grades are over 100. * * row 0: column titles row 1: weights row 2: full grades for testing row 3-: * actual students * * String studentDataCsv = "studentID,name,lastName,midterm,homework,lab\n"// + * "-1,-weight,percent,40,10,50\n"// percentages where studentID=-1 + * "-2,-full,point,100,100,100\n"// test for full points where studentID=-1 + * "1001,Aaa,Aaaa,50,50,50\n"// first student + "1002,Bbb,Bbbb,10,10,10"// * second student ; */ public class ProcessGradingData { public static final String MY_ID = "20221319027"; public static final String MY_NAME = "Deniz"; public static final String MY_LASTNAME = "Soysal"; public static final int WEIGHT = -1; public static final int FULL = -2; // public static final int S_ID = 0; public static final int S_NAME = 1; public static final int S_LAST_NAME = 2; public static final int MIDTERM = 3; public static final int HOMEWORK = 4; public static final int FINAL = 5; // public static double[] weight = new double[3]; /** * Student info * * @return */ public static String getStudentInfo() { return MY_ID + "," + MY_LASTNAME + "," + MY_NAME; } /** * Given two `Student`s, return `true` if the students are equal in content. * * @param stdA * @param stdB * @return `true` if the students are equal in content. */ public static boolean equals(Student stdA, Student stdB) { if (stdA.getStudentID() != stdB.getStudentID()) { return false; } if (!stdA.getName().equals(stdB.getName())) { return false; } if (stdA.getLab() != stdB.getLab()) { return false; } if (!stdA.getLastName().equals(stdB.getLastName())) { return false; } if (stdA.getHomework() != stdB.getHomework()) { return false; } if (stdA.getMidterm() != stdB.getMidterm()) { return false; } return true; } /** * Given `weight` array and `Student`, calculate the weighted grade * * @param weight * @param student * @return weighted grade */ public static double getWeightedGrade(double[] weight, Student student) { double grade = 0; grade += weight[0] * student.getMidterm(); grade += weight[1] * student.getHomework(); grade += weight[2] * student.getLab(); return grade; } /** * Convert student data in csv format into arrStudent and populate * `weight` array. * * @param csv student data * @return array of Students */ public static Student[] getStudentData(String csv) { String[] lines=csv.split("\n"); Student[] arrStudent = new Student[lines.length - 3] ; for (int i = 3; i < lines.length; i++) { String[] fields = lines[i].split(","); int Id = Integer.parseInt(fields[0]); String name = fields[1]; String lastName = fields[2]; int midterm = Integer.parseInt(fields[3]); int homework = Integer.parseInt(fields[4]); int lab = Integer.parseInt(fields[5]); Student student = new Student(Id,name,lastName,midterm,homework,lab); arrStudent[i-3] = student; } String[] fields = lines[1].split(","); weight[0] = Double.parseDouble(fields[3])/100; weight[1] = Double.parseDouble(fields[4])/100; weight[2] = Double.parseDouble(fields[5])/100; return arrStudent; } /** * Produce report of student number and weighted grade * * @param arrStudent * @return */ public static String[] getReport(Student[] arrStudent) { String[] arrGradesOverAll = new String [arrStudent.length]; for (int i = 0; i