Exemplo n.º 1
0
 public void removeClassroomID(Classroom classroomID)
 {
 }
Exemplo n.º 2
0
 public void addClassroom(Classroom classroom)
 {
     this.ClassroomList.Add(classroom);
 }
Exemplo n.º 3
0
 public void removeClassroom(Classroom classroom)
 {
 }
Exemplo n.º 4
0
        public Classroom setClassIDGroupID(Student student, EnrollmentRules rule)
        {
            bool      classroomFound  = false;
            bool      groupFound      = false;
            bool      teacherFound    = false;
            Classroom vacantClassroom = null;

            if (this.ClassroomList.Count == 0)
            {
                Classroom classObj = new Classroom(this.ClassroomList.Count, rule);
                classroomFound = true;
                this.addClassroom(classObj);
                Console.WriteLine("No classrooms available, new class created");
                Group groupObj = new Group(classObj.getNumOfGroups(), classObj.enrollmentRule);
                groupObj.ClassID = classObj.classroomID;
                Console.WriteLine("No groups available, new group created");
                classObj.addGroupObj(groupObj);
                //add teacher
                foreach (Teacher teacher in TeacherList)
                {
                    if (teacher.IsAvailable)
                    {
                        teacher.IsAvailable = false;
                        teacher.ClassID     = classObj.classroomID;
                        teacher.GroupID     = groupObj.GroupID;
                        groupObj.teacher    = teacher;
                        teacherFound        = true;
                        break;
                    }
                }

                if (groupObj.getGroupSize() + 1 <= groupObj.EnrollmentRule.GroupSize)
                {
                    groupFound = true;
                    groupObj.AddStudent(student);
                    student.GroupID = groupObj.GroupID;
                    Console.WriteLine("groupID set");
                    student.ClassID = classObj.classroomID;
                    Console.WriteLine("classID set");
                    return(classObj);
                }
            }
            else
            {
                foreach (Classroom classroom in this.ClassroomList)
                {
                    if (classroom.enrollmentRule.Equals(rule))
                    {
                        Console.WriteLine("classroom.getNumOfGroups()  " + classroom.getNumOfGroups() + "  classroom.getEnrollmentRule().getMaxGroup()  " + classroom.enrollmentRule.MaxGroup);
                        if (classroom.getNumOfGroups() <= classroom.enrollmentRule.MaxGroup)
                        {
                            if (classroom.getNumOfGroups() == classroom.enrollmentRule.MaxGroup)
                            {
                                Console.WriteLine("Classroom is full");
                                foreach (Group group in classroom.groupList)
                                {
                                    Console.WriteLine("group.getGroupSize()+1" + (group.getGroupSize() + 1) + " group.getEnrollmentRule().getGroupSize() " + group.EnrollmentRule.GroupSize);
                                    if (group.getGroupSize() + 1 <= group.EnrollmentRule.GroupSize)
                                    {
                                        Console.WriteLine("Group with vacancy found");
                                        groupFound     = true;
                                        classroomFound = true;
                                        group.AddStudent(student);
                                        student.GroupID = group.GroupID;
                                        Console.WriteLine("groupID set");
                                        student.ClassID = classroom.classroomID;
                                        Console.WriteLine("classID set");
                                        return(classroom);
                                    }
                                }
                            }
                            else
                            {
                                classroomFound  = true;
                                vacantClassroom = classroom;
                                foreach (Group group1 in classroom.groupList)
                                {
                                    Console.WriteLine("group.getGroupSize()+1" + (group1.getGroupSize() + 1) + " group.getEnrollmentRule().getGroupSize() " + group1.EnrollmentRule.GroupSize);
                                    if (group1.getGroupSize() + 1 <= group1.EnrollmentRule.MaxGroup)
                                    {
                                        Console.WriteLine("Group with vacancy found");
                                        groupFound = true;
                                        group1.AddStudent(student);
                                        student.GroupID = group1.GroupID;
                                        Console.WriteLine("groupID set");
                                        student.ClassID = classroom.classroomID;
                                        Console.WriteLine("classID set");
                                        return(classroom);
                                    }
                                    else
                                    {
                                        Console.WriteLine("Group is full");
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Classroom is full");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Class rule mismatch");
                    }
                    if (classroomFound == true && vacantClassroom != null)
                    {
                        Console.WriteLine("Vacant classroom available, group is full, creating new group");
                        Console.WriteLine("inputs for creating new group are " + vacantClassroom.getNumOfGroups() + "  " + vacantClassroom.enrollmentRule);
                        Group newGroup = new Group(vacantClassroom.getNumOfGroups(), vacantClassroom.enrollmentRule);
                        newGroup.ClassID = vacantClassroom.classroomID;
                        vacantClassroom.addGroupObj(newGroup);
                        //add teacher
                        foreach (Teacher teacher in TeacherList)
                        {
                            if (teacher.IsAvailable)
                            {
                                teacher.IsAvailable = false;
                                teacher.ClassID     = newGroup.ClassID;
                                teacher.GroupID     = newGroup.GroupID;
                                newGroup.teacher    = teacher;
                                teacherFound        = true;
                                break;
                            }
                        }
                        Console.WriteLine("check ***  " + newGroup.GroupID + "  " + (newGroup.getGroupSize() + 1) + "   " + newGroup.EnrollmentRule.GroupSize);
                        if (newGroup.getGroupSize() + 1 <= newGroup.EnrollmentRule.GroupSize)
                        {
                            groupFound = true;
                            newGroup.AddStudent(student);
                            student.GroupID = newGroup.GroupID;
                            Console.WriteLine("groupID set");
                            student.ClassID = vacantClassroom.classroomID;
                            Console.WriteLine("classID set");
                            return(vacantClassroom);
                        }
                    }
                }
            }
            Console.WriteLine("classroomFound is " + classroomFound + "  groupFound  " + groupFound);
            if (classroomFound == false && groupFound == false)
            {
                Console.WriteLine("Class and group not found");
                Console.WriteLine("Creating new class and group");
                Classroom classObj = new Classroom(this.ClassroomList.Count, rule);
                classroomFound = true;
                this.addClassroom(classObj);
                Group groupObj = new Group(classObj.getNumOfGroups(), classObj.enrollmentRule);
                groupObj.ClassID = classObj.classroomID;
                classObj.addGroupObj(groupObj);
                //add teacher
                foreach (Teacher teacher in TeacherList)
                {
                    if (teacher.IsAvailable)
                    {
                        teacher.IsAvailable = false;
                        teacher.ClassID     = groupObj.ClassID;
                        teacher.GroupID     = groupObj.GroupID;
                        groupObj.teacher    = teacher;
                        teacherFound        = true;
                        break;
                    }
                }
                if (groupObj.getGroupSize() + 1 <= groupObj.EnrollmentRule.GroupSize)
                {
                    groupFound = true;
                    groupObj.AddStudent(student);
                    student.GroupID = groupObj.GroupID;
                    Console.WriteLine("groupID set");
                    student.ClassID = classObj.classroomID;
                    Console.WriteLine("classID set");
                    return(classObj);
                }
            }
            throw new Exception("Invalid input while assigning Class ID");
        }