-
Notifications
You must be signed in to change notification settings - Fork 0
/
GradeCalculator.java
153 lines (139 loc) · 4.88 KB
/
GradeCalculator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.util.ArrayList;
/**
* The `GradeCalculator` class provides methods to calculate and retrieve
* grades, Quality Credit Score (QCS),
* and Quality Credit Average (QCA) for modules, semesters, and courses based on
* a grading scheme.
*/
public class GradeCalculator {
/**
* Retrieves the grade for a given student in a specific module.
*
* @param module The module for which the grade is to be determined.
* @param id The student ID.
* @return The calculated grade.
*/
public static String getGrade(Module module, String id) {
String file = module.getFile();
ArrayList<Double> studentResults = CSVReader.readStudentResult(file, id);
int[] bounds = new int[12];
String[] grades = new String[12];
try {
CSVReader.readGradingScheme("GradingScheme.csv", bounds, grades);
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
}
double total = 0;
int index = 0;
for (Double results : studentResults) {
total += results;
}
for (int i = 0; i < bounds.length; i++) {
if (total > bounds[i]) {
index = i;
}
}
return grades[index];
}
/**
* Calculates the Quality Credit Score (QCS) for a given student in a specific
* module.
*
* @param module The module for which QCS is to be calculated.
* @param id The student ID.
* @return The calculated QCS.
*/
public static double calculateQCS(Module module, String id) {
String grade = getGrade(module, id);
double modCredits = module.getCredits();
double modQCA = 0.0;
if (grade.equals("A1")) {
modQCA += 4.0;
} else if (grade.equals("A2")) {
modQCA += 3.6;
} else if (grade.equals("B1")) {
modQCA += 3.2;
} else if (grade.equals("B2")) {
modQCA += 3.0;
} else if (grade.equals("B3")) {
modQCA += 2.8;
} else if (grade.equals("C1")) {
modQCA += 2.6;
} else if (grade.equals("C2")) {
modQCA += 2.4;
} else if (grade.equals("C3")) {
modQCA += 2.0;
} else if (grade.equals("D1")) {
modQCA += 1.6;
} else if (grade.equals("D2")) {
modQCA += 1.2;
} else if (grade.equals("F")) {
modQCA += 0.00;
} else if (grade.equals("NG")) {
modQCA += 0.00;
}
double modQCS = modQCA * modCredits;
return modQCS;
}
/**
* Calculates the Quality Credit Average (QCA) for a given student in a specific
* semester.
*
* @param semester The semester for which QCA is to be calculated.
* @param id The student ID.
* @return The calculated QCA.
*/
public static double calculateQCA(Semester semester, String id) {
double semCredits = semester.getCredits();
ArrayList<Module> mods = semester.getModules();
double modQCS = 0;
double QCS = 0;
double semQCA = 0;
for (int i = 0; i < mods.size(); i++) {
modQCS = calculateQCS(mods.get(i), id);
QCS += modQCS;
}
semQCA = QCS / semCredits;
return semQCA;
}
/**
* Calculates the Quality Credit Average (QCA) for a given student in a specific
* semester and course.
*
* @param course The course to which the semester belongs.
* @param semester The semester for which QCA is to be calculated.
* @param id The student ID.
* @return The calculated QCA.
*/
public static double calculateQCA(Course course, Semester semester, String id) {
ArrayList<Semester> semNum = course.getSemesters();
double semWeighting = semester.getWeighting();
double semQCA = 0;
double semCredits = semester.getCredits();
double totalQCA = 0;
double totalCredits = 0;
double finalQCA = 0;
for (int i = 0; i < semNum.size(); i++) {
semQCA = calculateQCA(semNum.get(i), id);
if (semWeighting > 0) {
totalCredits += semCredits * semWeighting;
} else {
totalCredits += semCredits;
}
totalQCA += semQCA;
}
finalQCA = totalQCA / totalCredits;
return finalQCA;
// if (finalQCA >= 3.40) {
// System.out.println("First class honours");
// } else if (finalQCA < 3.40 && finalQCA >= 3.00) {
// System.out.println("Second class honours grade 1 (2.1)");
// } else if (finalQCA < 3.00 && finalQCA >= 2.60) {
// System.out.println("Second class honours grade 2 (2.2)");
// } else if (finalQCA < 2.60 && finalQCA >= 2.00) {
// System.out.println("Third class honours");
// } else {
// System.out.println("");
// }
}
}