diff --git a/src/main/java/org/example/Student.java b/src/main/java/org/example/Student.java index 4917f2e..02b0053 100644 --- a/src/main/java/org/example/Student.java +++ b/src/main/java/org/example/Student.java @@ -128,4 +128,18 @@ public class Student { return totalCredits; } + public double calculateAverageGrade() { + double totalWeightedGrades = 0.0; + int totalCredits = calculateTotalCredits(); // Use the existing method to get the total credits + + for (Map.Entry 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; + } }