private double calculateStudentTotalGradePercentage(StudentViewModel student) { int totalCoursePoints = 0; int totalStudentPoints = 0; foreach (GradingPeriodViewModel gradingPeriod in this.gradingPeriods) { CourseViewModel course = findCourse(gradingPeriod); totalCoursePoints += course.getTotalPoints(); totalStudentPoints += course.getStudentPoints(student); } if (totalCoursePoints == 0) { return(1.0); } return(Convert.ToDouble(totalStudentPoints) / Convert.ToDouble(totalCoursePoints)); }