public void AddUnitGrade(UnitGrade unitgrade) { if (unitgrade == null) { throw new ArgumentException("Cannot add a null unitgrade to trimester performance"); } unitGrades.Add(unitgrade); }
public override bool Equals(object obj) { if ((obj == null) || (obj.GetType() != typeof(UnitGrade))) { return(false); } UnitGrade compGrade = (UnitGrade)obj; if (compGrade.unitCode == unitCode) { return(true); } else { return(false); } }
public void CheckPrerequisites(List <StudyUnit> studyUnits) { if (studyUnits == null) { throw new ArgumentException("CheckPrerequisites cannot be run with a null argument"); } List <string> tempString = new List <string>(); List <Trimesters> tempTrimesters = new List <Trimesters>(); List <Campuses> tempCampuses = new List <Campuses>(); List <UnitGrade> unitGrades, previousGrades; StudyUnit tempUnit, locatedUnit; UnitGrade tempUnitGrade, locatedUnitGrade; int indexLocation; List <string> prerequisites; bool foundPrerequisite; string exceptionMessage = ""; if (trimesterPerformanceList == null) { return; } for (int i = 0; i < trimesterPerformanceList.Count; i++) { unitGrades = trimesterPerformanceList[i].unitGrades; for (int j = 0; j < unitGrades.Count; j++) { tempUnit = new StudyUnit(unitGrades[j].unitCode, unitGrades[j].unitName, tempString, 0, UnitClassification.elective, tempTrimesters, tempCampuses, tempString, 40); locatedUnit = studyUnits[studyUnits.IndexOf(tempUnit)]; prerequisites = locatedUnit.prerequisites; for (int k = 0; k < locatedUnit.prerequisites.Count; k++) { foundPrerequisite = false; for (int m = i - 1; m >= 0; m--) { previousGrades = trimesterPerformanceList[m].unitGrades; tempUnitGrade = new UnitGrade(prerequisites[k], " ", 0); indexLocation = previousGrades.IndexOf(tempUnitGrade); if (indexLocation >= 0) { locatedUnitGrade = previousGrades[indexLocation]; if (locatedUnitGrade.mark > locatedUnitGrade.gradingScheme.gradeRanges[0]) { foundPrerequisite = true; break; } } } if (!foundPrerequisite) { exceptionMessage += "Unit : " + unitGrades[j].unitCode + " has prerequisite " + locatedUnit.prerequisites[k] + " which has not been fulfilled yet\n"; } } } } if (exceptionMessage.Length > 1) { throw new ArgumentException(exceptionMessage); } }
public TrimesterPerformance CreateTrimesterPerformance(List <string> strings) { if (strings == null) { throw new ArgumentException("CreateTrimesterPerformance cannot be run on a null string list"); } char[] delimiters = new char[] { ' ' }; string exceptionMessage = ""; TrimesterMonths month = TrimesterMonths.JAN; Trimesters trimester = Trimesters.Y1T1; int year = 0; IEnumerator ie = strings.GetEnumerator(); ie.MoveNext(); string[] elements = ((string)ie.Current).Trim().Split(delimiters, StringSplitOptions.RemoveEmptyEntries); if (elements.Length != 3) { for (int i = 0; i < elements.Length; i++) { exceptionMessage += elements[i] + " "; } throw new ArgumentException(exceptionMessage + ": " + DefaultValues.ExceptionMessages[12]); } try { year = Convert.ToInt32(elements[0]); } catch (Exception) { exceptionMessage += DefaultValues.ExceptionMessages[13] + "\n"; } try { month = (TrimesterMonths)Enum.Parse(typeof(TrimesterMonths), elements[1].ToUpper()); } catch (Exception) { exceptionMessage += DefaultValues.ExceptionMessages[14] + "\n"; } try { trimester = (Trimesters)Enum.Parse(typeof(Trimesters), elements[2].ToUpper()); } catch (Exception) { exceptionMessage += DefaultValues.ExceptionMessages[15] + "\n"; } if (exceptionMessage.Length > 1) { throw new ArgumentException(elements[0] + " " + elements[1] + " " + elements[2] + " : " + exceptionMessage); } TrimesterPerformance trimesterPerformance = new TrimesterPerformance(year, month, trimester); string curLine; string[] components; UnitGrade ugrade; int mark = 0; while (ie.MoveNext()) { curLine = (string)ie.Current; components = curLine.Trim().Split(':'); if (components.Length != 3) { exceptionMessage += (year + " " + month + " " + trimester) + " : " + DefaultValues.ExceptionMessages[16]; throw new ArgumentException(exceptionMessage); } try { mark = Convert.ToInt32(components[2]); } catch (Exception) { exceptionMessage += components[0].Trim() + " : " + DefaultValues.ExceptionMessages[17]; throw new ArgumentException(exceptionMessage); } ugrade = new UnitGrade(components[0].Trim(), components[1].Trim(), mark); ugrade.gradingScheme = new GradingScheme(); ugrade.CalculateGrade(); trimesterPerformance.AddUnitGrade(ugrade); } return(trimesterPerformance); }
public List <StudentRecord> GenerateStudentRecords(int numToGenerate, StudentRecord courseStructure, List <string> maleNames, List <string> femaleNames, List <string> surNames) { if ((numToGenerate < 0) || (courseStructure == null) || (maleNames == null) || (femaleNames == null) || (surNames == null)) { throw new ArgumentException("GenerateStudentRecords cannot be run with null or invalid arguments"); } List <StudentRecord> records = new List <StudentRecord>(); StudentRecord studRecord; string studName = ""; string idnumber = ""; Gender studGender; for (int i = 0; i < numToGenerate; i++) { studGender = (Gender)rndFunction.ReturnRandomNumber(0, 2); if (studGender == Gender.male) { studName = maleNames[rndFunction.ReturnRandomNumber(0, maleNames.Count)]; } else if (studGender == Gender.female) { studName = femaleNames[rndFunction.ReturnRandomNumber(0, femaleNames.Count)]; } studName += " " + surNames[rndFunction.ReturnRandomNumber(0, surNames.Count)]; idnumber = courseStructure.programme + rndFunction.ReturnRandomNumber(1000, 10000) + i; studRecord = new StudentRecord(studName, idnumber, studGender, studName + DefaultValues.dummyEmailAdd, DefaultValues.dummyContactNumber, courseStructure.programme, courseStructure.creditHrsToGraduate); List <UnitGrade> newGradeList = new List <UnitGrade>(); UnitGrade tempGrade; TrimesterPerformance tempTrimester; int gradeMark; foreach (TrimesterPerformance tpf in courseStructure.trimesterPerformanceList) { tempTrimester = new TrimesterPerformance(tpf.year, tpf.month, tpf.trimester); newGradeList = new List <UnitGrade>(); foreach (UnitGrade ugrade in tpf.unitGrades) { if (rndFunction.ReturnRandomNumber(0, 5) == 1) { gradeMark = rndFunction.ReturnRandomNumber(0, 51); } else { gradeMark = rndFunction.ReturnRandomNumber(51, 100); } tempGrade = new UnitGrade(ugrade.unitCode, ugrade.unitName, gradeMark); tempGrade.CalculateGrade(); newGradeList.Add(tempGrade); } tempTrimester.unitGrades = newGradeList; studRecord.AddTrimesterPerformance(tempTrimester); } records.Add(studRecord); } return(records); }