public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { var credits = 0; var average = 0; var relevantCourses = 0; var requirements = diploma.Requirements.Select(x => Repository.GetRequirement(x)); foreach (var requirement in requirements) { var studentCourse = student.Courses.FirstOrDefault(x => x.Id == requirement.Course); if (studentCourse != null) { relevantCourses += 1; average += studentCourse.Mark; if (studentCourse.Mark >= requirement.MinimumMark) { credits += requirement.Credits; } } } average = average / relevantCourses; var standing = StandingsHelper.GetStandingFromMark(average); if (StandingsHelper.IsPassingGrade(average) && credits >= diploma.Credits) { return(new Tuple <bool, STANDING>(true, standing)); } return(new Tuple <bool, STANDING>(false, standing)); }
public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { var credits = 0; int sumOfMarks = 0; var requirementsForDiploma = diploma.Requirements; Dictionary <int, int> CoursesIDCreaditToPassList = new Dictionary <int, int>(); foreach (var requiredId in requirementsForDiploma) { CoursesIDCreaditToPassList.Add(_repository.GetRequirement(requiredId).Courses[0], _repository.GetRequirement(requiredId).Credits); } List <int> CourseIDStudendHasPassed = new List <int>(); foreach (var course in student.Courses) { CourseIDStudendHasPassed.Add(course.Id); sumOfMarks += course.Mark; credits += CoursesIDCreaditToPassList.FirstOrDefault(x => x.Key == course.Id).Value; } if (CourseIDStudendHasPassed.All(CoursesIDCreaditToPassList.Keys.ToList().Contains) && credits == diploma.Credits) { return(CalculateAverage(sumOfMarks, student.Courses.Length)); } else { return(new Tuple <bool, STANDING>(false, STANDING.Remedial)); } }
public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { int credits = 0, average = 0; for (int i = 0, j = 0; i < diploma.Requirements.Length && j < student.Courses.Length; i++, j++) { var requirement = Repository.GetRequirement(diploma.Requirements[i]); for (int k = 0; k < requirement.Courses.Length; k++) { if (requirement.Courses[k] == student.Courses[j].Id) { average += student.Courses[j].Mark; if (student.Courses[j].Mark > requirement.MinimumMark) { credits += requirement.Credits; } } } } average /= student.Courses.Length; STANDING standing; if (average < 50) { standing = STANDING.Remedial; } else if (average < 80) { standing = STANDING.Average; } else if (average < 95) { standing = STANDING.SumaCumLaude; } else { standing = STANDING.MagnaCumLaude; } switch (standing) { case STANDING.Remedial: return(new Tuple <bool, STANDING>(false, standing)); case STANDING.Average: return(new Tuple <bool, STANDING>(true, standing)); case STANDING.SumaCumLaude: return(new Tuple <bool, STANDING>(true, standing)); case STANDING.MagnaCumLaude: return(new Tuple <bool, STANDING>(true, standing)); default: return(new Tuple <bool, STANDING>(false, standing)); } }
public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { var average = 0; foreach (var diplomaRequirement in diploma.Requirements) { var courseRequirement = Repository.GetRequirement(diplomaRequirement); var studentMark = student.Courses.Single(c => c.Name == courseRequirement.Name).Mark; average += studentMark; } average /= student.Courses.Length; if (average < 50) { return(new Tuple <bool, STANDING>(false, STANDING.Remedial)); } else if (average < 80) { return(new Tuple <bool, STANDING>(true, STANDING.Average)); } else if (average < 95) { return(new Tuple <bool, STANDING>(true, STANDING.SumaCumLaude)); } else { return(new Tuple <bool, STANDING>(true, STANDING.MagnaCumLaude)); } }
public ReportCard GetReportCard(Diploma diploma, Student student) { var result = new ReportCard() { DiplomaId = diploma.Id, StudentId = student.Id }; var gradeSum = 0; var totalRequiredCoursesTakenForDiploma = 0; foreach (var requirementId in diploma.Requirements) { // Need to check if the student meets this requirement. var requirement = Repository.GetRequirement(requirementId); // Get all the courses the student has taken that are part of the requirement. var requirementCoursesTakenByStudent = student.Courses.Where(c => requirement.CourseIds.Contains(c.Id)); // Increment total number of courses taken for this diploma totalRequiredCoursesTakenForDiploma += requirementCoursesTakenByStudent.Count(); // Aggregate the marks obtained. gradeSum += requirementCoursesTakenByStudent.Sum(c => c.Mark); // Aggregate credits if mark meets minimum requirement result.Credits += requirementCoursesTakenByStudent .Where(c => c.Mark > requirement.MinimumMark) .Sum(c => requirement.Credits); } result.Average = gradeSum / totalRequiredCoursesTakenForDiploma; return(result); }
public Tuple <bool, Standing> HasGraduated(Diploma diploma, Student student) { int average = 0; CalculateAverage(diploma, student, ref average); return(CheckGraduation(average)); }
private static int CalculateAverage(Diploma diploma, Student student) { int average = 0; for (int i = 0; i < diploma.Requirements.Length; i++) { for (int j = 0; j < student.Courses.Length; j++) { var requirement = Repository.GetRequirement(diploma.Requirements[i]); for (int k = 0; k < requirement.Courses.Length; k++) { if (requirement.Courses[k] == student.Courses[j].Id) { average += student.Courses[j].Mark; if (student.Courses[j].Mark >= requirement.MinimumMark) { student.Credits += requirement.Credits; } } } } } return(average); }
public static Diploma GetDiploma(int id) { var diplomas = GetDiplomas(); IGraduation <Diploma> obj = new Diploma(); return(obj.GetObjectByID(diplomas, id)); }
public Standing HasGraduated(Diploma diploma, Student student) { foreach (Requirement req in diploma.Requirements) { bool requirementMet = _requirementsService.CreditsFulfilled(req, student); if (!requirementMet) { return(Standing.CreditsUnfulfilled); } } // Here I am making an assumption. I don't have enough information // on how the average is calculated. The original code is rather confusing: // it first totals the marks of the cources which ARE on the requirement but // then it divides that total by the number of cources the student completed // You have to pick one or the other: either compute the average of all cources the // student took OR compute the average of the REQUIRED cources. I picked the total // of the student completed cources int average = _requirementsService.GetStudentAverage(student); if (average < 50) { return(Standing.Remedial); } if (average < 80) { return(Standing.Average); } if (average < 95) { return(Standing.MagnaCumLaude); } return(Standing.MagnaCumLaude); }
/// <summary> /// This Method based on Average checks whether the student is graduated or not. /// </summary> /// <param name="diploma"></param> /// <param name="student"></param> /// <returns>tuple of whether graduated and standing</returns> public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { var credits = 0; var average = 0; int totalCourses = 0; for (int i = 0; i < diploma.Requirements.Length; i++) { var requirement = repository.GetRequirement(diploma.Requirements[i]); var requiredCoursesCompleted = student.Courses.Where(c => requirement.Courses.Contains(c.Id)); average += requiredCoursesCompleted.Sum(c => c.Mark); credits += requiredCoursesCompleted.Where(rcp => rcp.Mark > requirement.MinimumMark).Count() * requirement.Credits; totalCourses = requirement.Courses.Count(); } average = average / totalCourses; // No Case for STANDING.SumaCumLaude defined: requirement not clear if (average < 50) { return(new Tuple <bool, STANDING>(false, STANDING.Remedial)); } else if (average < 80) { return(new Tuple <bool, STANDING>(true, STANDING.Average)); } else if (average < 95) { return(new Tuple <bool, STANDING>(true, STANDING.MagnaCumLaude)); } else { return(new Tuple <bool, STANDING>(false, STANDING.MagnaCumLaude)); } }
public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { try { var creditsAverage = GetCreditAverage(diploma, student); var standing = GetStanding(creditsAverage.Item2); // Not enough credits if (creditsAverage.Item1 < diploma.Credits) { return(new Tuple <bool, STANDING>(false, STANDING.Remedial)); } else if (standing == STANDING.Remedial || standing == STANDING.None) { return(new Tuple <bool, STANDING>(false, standing)); } else { return(new Tuple <bool, STANDING>(true, standing)); } } catch (Exception ex) { return(new Tuple <bool, STANDING>(false, STANDING.None)); } }
/// <summary> /// /// </summary> /// <param name="diploma"></param> /// <param name="student"></param> /// <returns></returns> public Tuple <bool, STANDING, int> HasGraduated(Diploma diploma, Student student) { var credits = 0; var sumOfMarks = 0; for (int i = 0; i < diploma.Requirements.Length; i++) { for (int j = 0; j < student.Courses.Length; j++) { var requirement = _repository.GetRequirement(diploma.Requirements[i]); for (int k = 0; k < requirement.Courses.Length; k++) { if (requirement.Courses[k] == student.Courses[j].Id) { sumOfMarks += student.Courses[j].Mark; if (student.Courses[j].Mark > requirement.MinimumMark) { credits += requirement.Credits; } } } } } var averageMark = sumOfMarks / student.Courses.Length; //credits added to have ability to create unit test return(new Tuple <bool, STANDING, int>(StudentHasGraduated(averageMark), StudentStanding(averageMark), credits)); }
private void UpdateCredits(Diploma diploma, Student student, ref int credits, ref int average, IRepository repo) { try { for (int i = 0; i < diploma.Requirements.Length; i++) { for (int j = 0; j < student.Courses.Length; j++) { var requirement = repo.GetRequirement(diploma.Requirements[i]); for (int k = 0; k < requirement.Courses.Length; k++) { if (requirement.Courses[k] == student.Courses[j].Id) { average += student.Courses[j].Mark; if (student.Courses[j].Mark > requirement.MinimumMark) { credits += requirement.Credits; } } } } } } catch (Exception ex) { _logger.LogError(ex.Message.ToString()); } }
private static float GetAverage(Diploma Diploma, Student Student) { int Credits = 0; float Marks = 0; for (int i = 0; i < Diploma.Requirements.Length; i++) { for (int j = 0; j < Student.Courses.Length; j++) { Requirement Requirement = Requirement.GetRequirement(Diploma.Requirements[i]); for (int k = 0; k < Requirement.Courses.Length; k++) { if (Requirement.Courses[k] == Student.Courses[j].Id) { Marks += Student.Courses[j].Mark; if (Student.Courses[j].Mark > Requirement.MinimumMark) { Credits += Requirement.Credits; } } } } } return(Marks / Student.Courses.Length); }
public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { var credits = 0; var average = 0; for (int i = 0; i < diploma.Requirements.Length; i++) { for (int j = 0; j < student.Courses.Length; j++) { var requirement = _appIRepository.GetRequirement(diploma.Requirements[i]); for (int k = 0; k < requirement.Courses.Length; k++) { if (requirement.Courses[k] == student.Courses[j].Id) { average += student.Courses[j].Mark; if (student.Courses[j].Mark > requirement.MinimumMark) { credits += requirement.Credits; } } } } } average = average / student.Courses.Length; return(GetStanding(average)); }
/// <summary> /// Function calculates average of student and provides an appropriate standing based on the result /// </summary> /// <param name="diploma">Contains the IDs of Required Courses</param> /// <param name="student">Contains List of Courses the Student Undertook</param> /// <returns>A tuple value that contains a boolean value and the standing</returns> public Tuple <bool, Standing> HasGraduated(Diploma diploma, Student student) { //Removed the variable "credits" as it wasn't used anywhere in the program. var average = 0; //Performed validations before executing the Expression to avoid any exceptions if (diploma != null && student != null && !student.Courses.Count().Equals(0)) { average = diploma.Requirements.Where(requirementId => new Repository <RequirementRepository>().FetchRecordByID(requirementId) != null) .Select(requirementId => student.Courses.Where(courseSelector => courseSelector.Id.Equals(requirementId)) .Select(courseSelector => courseSelector.Mark) .Sum()).Sum() / student.Courses.Count(); } //Renamed and Moved the "GetRequirement" function above the Student Loop to reduce the amount of database call //Adding the marks of the course selector imperatively as all the conditions statisfy and perform an average //Removed unecessary "standing" variable as the same can be achieved by directly accessing the enum-constant return (average == 0 ? new Tuple <bool, Standing>(false, Standing.None) : average < 50 ? new Tuple <bool, Standing>(false, Standing.Remedial) : average < 80 ? new Tuple <bool, Standing>(true, Standing.Average) : average < 95 ? new Tuple <bool, Standing>(true, Standing.MagnaCumLaude) : new Tuple <bool, Standing>(true, Standing.SumaCumLaude)); }
public Diploma GetDiploma(int id) { var diplomas = GetDiplomas(); Diploma diploma = diplomas.SingleOrDefault(x => x.Id == id); return(diploma); }
public static Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { int average = CalculateAverage(diploma, student) / student.Courses.Length; bool reqCreditsEarned = RequiredCreditsEarned(diploma, student); student.Standing = DetermineStanding(average, reqCreditsEarned); return(new Tuple <bool, STANDING>(reqCreditsEarned && student.Standing > STANDING.Remedial, student.Standing)); }
public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { Tuple <bool, STANDING> result = new Tuple <bool, STANDING>(false, STANDING.None); if (diploma == null || student == null || diploma.Requirements == null) { return(result); } var credits = 0; int totalMarks = 0; var courseRequirements = repository.GetCourseRequirements(); for (int i = 0; i < diploma.Requirements.Length; i++) { var courseRequirement = courseRequirements.Where(cr => cr.Id == diploma.Requirements[i]).FirstOrDefault(); if (courseRequirement == null) { continue; } var courseMark = student.CourseMarks.Where(m => m.CourseId == courseRequirement.CourseId).FirstOrDefault(); if (courseMark == null) { continue; } totalMarks += courseMark.Mark; if (courseMark.Mark > courseRequirement.MinimumMark) { credits += courseRequirement.Credits; } } var average = totalMarks / student.CourseMarks.Length; if (average < 50) { result = new Tuple <bool, STANDING>(false, STANDING.Remedial); } else if (average < 80) { result = new Tuple <bool, STANDING>(true, STANDING.Average); } else if (average < 95) { result = new Tuple <bool, STANDING>(true, STANDING.MagnaCumLaude); } else { result = new Tuple <bool, STANDING>(true, STANDING.SumaCumLaude); } return(result); }
/// <summary> /// Check if the Student has been graduated /// </summary> /// <param name="diploma">Diploma to match with student courses</param> /// <param name="student">Student information</param> /// <returns>Tuple informing has graduated/Standing/Credits</returns> public Tuple <bool, STANDING, int> HasGraduated(Diploma diploma, Student student) { bool graduated = false; int credits = 0; var average = 0; foreach (Requirement iDipReq in diploma.Requirements) { //Get the diploma's requirement Requirement reqCourse = BRequirement.GetRequirement(iDipReq.Id); foreach (Course iStuCou in student.Courses) { //Check if the current student course belongs to the diploma's requirement course if (reqCourse.Courses.SingleOrDefault(x => x.Id == iStuCou.Id) != null) { average += iStuCou.Mark; if (iStuCou.Mark > reqCourse.MinimumMark) { credits += reqCourse.Credits; } } } } average = average / student.Courses.Count; var standing = STANDING.None; if (average < 50) { standing = STANDING.Remedial; graduated = false; } else if (average < 80) { standing = STANDING.Average; graduated = true; } else if (average < 95) { standing = STANDING.MagnaCumLaude; graduated = true; } else { standing = STANDING.MagnaCumLaude; graduated = true; } return(new Tuple <bool, STANDING, int>(graduated, standing, credits)); }
public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { // Ensure that all requirements are met var meetsRequirements = diploma.Requirements.All(rId => CoursesMeetRequirement(rId, student.Courses)); // Calculate average grade and total credits var credits = 0; var average = 0; foreach (var course in student.Courses) { // Only passed courses count toward total credits if (course.Mark >= 50) { credits += course.Credits; } // All courses count toward average average += course.Mark; } average = average / student.Courses.Length; var standing = STANDING.None; if (average >= 100) { standing = STANDING.SumaCumLaude; } else if (average >= 80) { standing = STANDING.MagnaCumLaude; } else if (average >= 50) { standing = STANDING.Average; } else { standing = STANDING.Remedial; } // In order to graduate a student must: // 1. have the minimum average grade (>=50) // 2. AND have met all of the specified requirements // 3. AND have earned the minimum number of credits var graduated = ( standing != STANDING.Remedial && meetsRequirements && credits >= diploma.Credits ); return(new Tuple <bool, STANDING>(graduated, standing)); }
public static Diploma GetDiploma(int id) { var diplomas = GetDiplomas(); Diploma diploma = null; for (int i = 0; i < diplomas.Length; i++) { if (id == diplomas[i].Id) { diploma = diplomas[i]; } } return(diploma); }
public static Diploma GetDiploma(int Id) { Diploma[] Diplomas = Repository.GetDiplomas(); Diploma Diploma = null; for (int i = 0; i < Diplomas.Length; i++) { if (Id == Diplomas[i].Id) { Diploma = Diplomas[i]; } } return(Diploma); }
public ResultGraduationTraker HasGraduated(Diploma diploma, Student student) { IEnumerable <RequirementCoursesMark> requirementCoursesMark = this.GetRequirementCoursesMarkData(diploma, student); decimal averageMark = this.GetAvarageMark(requirementCoursesMark, student); int totalCredit = this.GetTotalCredit(requirementCoursesMark); student.Standing = this.GetStudentStanding(averageMark); return(new ResultGraduationTraker { Graduated = this.IsGraduated(student.Standing), Standing = student.Standing, TotalCredits = totalCredit }); }
public Tuple <bool, Standing> HasGraduated(Diploma diploma, Student student) { var average = 0; var countCourses = 0; var requirements = diploma.Requirements; for (int i = 0; i < requirements.Length; i++) { var requirement = repository.GetRequirement(requirements[i]); average += student.Courses.Where(c => requirement.Courses.Contains(c.Id)).Sum(c => c.Mark); countCourses = requirement.Courses.Count(); } return(CalculateStanding(average / countCourses)); }
/// <summary> /// To check if a student has graduated; determined by the student standing /// </summary> /// <param name="diploma">The diploma object</param> /// <param name="student">The student object</param> /// <returns>A 3-Tuple</returns> public Tuple <bool, STANDING, int> HasGraduated(Diploma diploma, Student student) { var credits = 0; var average = 0; // get student's average average = GetStudentAverage(student, diploma.Requirements, out credits); // get student standing with the calculated average var standing = GetStandingByAverage(average); var graduated = (standing == STANDING.Average || standing == STANDING.SumaCumLaude || standing == STANDING.MagnaCumLaude) ? true : false; return(new Tuple <bool, STANDING, int>(graduated, standing, credits)); }
/// <summary> /// This function computes a student's average score and total credits for a given diploma program /// </summary> /// <param name="student"></param> /// <param name="diploma"></param> /// <param name="diplomareqId"></param> public void getStudentReqCreditsandAverage(Student student, Diploma diploma, int diplomareqId) { foreach (var stdcourse in student.Courses) { var requirement = Repository.GetRequirement(diplomareqId); foreach (int reqcourseId in requirement.Courses) { if (requirement.Courses.Contains(stdcourse.Id)) { average += stdcourse.Mark; credits += stdcourse.Mark > requirement.MinimumMark ? requirement.Credits : 0; } } } }
public static Diploma GetDiploma(int id) { var diplomas = GetDiplomas(); Diploma diploma = null; diploma = diplomas.FirstOrDefault(d => d.Id.Equals(id)); //for (int i = 0; i < diplomas.Length; i++) //{ // if (id == diplomas[i].Id) // { // diploma = diplomas[i]; // } //} return(diploma); }
public Tuple <bool, Standing> HasGraduated(Diploma diploma, Student student) { int credits = 0; var average = 0; for (int i = 0; i < diploma.Requirements.Length; i++) { for (int j = 0; j < student.Courses.Length; j++) { Requirement requirement = RequirementRepository.GetById(diploma.Requirements[i]); for (int k = 0; k < requirement.Courses.Length; k++) { if (requirement.Courses[k] == student.Courses[j].Id) { average += student.Courses[j].Mark; if (student.Courses[j].Mark > requirement.MinimumMark) { credits += requirement.Credits; } } } } } average /= student.Courses.Length; Standing standing = GetStanding(average); switch (standing) { case Standing.Remedial: return(new Tuple <bool, Standing>(false, standing)); case Standing.Average: return(new Tuple <bool, Standing>(true, standing)); case Standing.SumaCumLaude: return(new Tuple <bool, Standing>(true, standing)); case Standing.MagnaCumLaude: return(new Tuple <bool, Standing>(true, standing)); default: return(new Tuple <bool, Standing>(false, standing)); } }
public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student) { credits = 0; average = 0; //calculate student credits and average score for each diploma requirement diploma.Requirements.ToList().ForEach(x => getStudentReqCreditsandAverage(student, diploma, x)); average = average / student.Courses.Length; var standing = STANDING.None; if (average < 50) { standing = STANDING.Remedial; } else if (average < 80) { standing = STANDING.Average; } else if (average < 95) { standing = STANDING.MagnaCumLaude; } else { standing = STANDING.SumaCumLaude; } switch (standing) { case STANDING.Remedial: return(new Tuple <bool, STANDING>(false, standing)); case STANDING.Average: return(new Tuple <bool, STANDING>(true, standing)); case STANDING.SumaCumLaude: return(new Tuple <bool, STANDING>(true, standing)); case STANDING.MagnaCumLaude: return(new Tuple <bool, STANDING>(true, standing)); default: return(new Tuple <bool, STANDING>(false, standing)); } }