|
@ -128,4 +128,18 @@ public class Student { |
|
|
return totalCredits; |
|
|
return totalCredits; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public double calculateAverageGrade() { |
|
|
|
|
|
double totalWeightedGrades = 0.0; |
|
|
|
|
|
int totalCredits = calculateTotalCredits(); // Use the existing method to get the total credits |
|
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<Course, String> entry : courseGrades.entrySet()) { |
|
|
|
|
|
Course course = entry.getKey(); |
|
|
|
|
|
double grade = Double.parseDouble(entry.getValue()); // Assuming grades are stored as String and can be parsed to double |
|
|
|
|
|
int credits = course.getCourseCredits(); |
|
|
|
|
|
|
|
|
|
|
|
totalWeightedGrades += grade * credits; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return totalCredits > 0 ? totalWeightedGrades / totalCredits : 0.0; |
|
|
|
|
|
} |
|
|
} |
|
|
} |