public static void ScheduleClassCompatibility(int errorLimit, int maxClassSize) { //Establish Variables Schedule schedule = new Schedule(); List <Classes> ClassList = ClassesDB.ClassLoad(); List <Student> StudentList = StudentDB.StudentLoad(); int errorCount = 0; //Compares students from each class and determines which classes have no matches for (int i = 0; i < ClassList.Count; i++) //Loops through all classes { List <Student> studentList1 = ClassesDB.ClassStudentFind(ClassList[i]); //List for current class List <Classes> CompatibleClasses = new List <Classes>(); List <Classes> IncompatibleClasses = new List <Classes>(); List <int> incompatibleErrors = new List <int>(); for (int x = i + 1; x < ClassList.Count; x++) //Loops through all classes and compares to existing class { List <Student> studentList2 = ClassesDB.ClassStudentFind(ClassList[x]); //List for compared class foreach (Student student1 in studentList1) { foreach (Student student2 in studentList2) { if (ClassList[i].TeacherID == ClassList[x].TeacherID) { errorCount += 10; } if (student1.StudentID == student2.StudentID) { errorCount++; } } } if (errorCount > errorLimit) { IncompatibleClasses.Add(ClassList[x]); incompatibleErrors.Add(errorCount); } else { CompatibleClasses.Add(ClassList[x]); } } schedule.PrincipleClass = ClassList[i]; schedule.CompatibleClasses = CompatibleClasses; schedule.IncompatibleClasses = IncompatibleClasses; schedule.IncompatibleErrors = incompatibleErrors; //Save File.Delete(@"Data\Schedule\ScheduleData_" + i + ".json"); string fileName = @"Data\Schedule\ScheduleData_" + i + ".json"; string json = JsonConvert.SerializeObject(schedule); using (StreamWriter writer = new StreamWriter(fileName, false)) { writer.WriteLine(json); } } }