Browse Source

Added : added calculateAverageGrade() in Class Student

remotes/origin/fdai7600
fdai7600 11 months ago
parent
commit
4d87255371
  1. 14
      src/main/java/org/example/Student.java

14
src/main/java/org/example/Student.java

@ -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;
}
} }
Loading…
Cancel
Save