コード例 #1
0
        public static Room getRoom(int studentAgeInMonths, Person tc)
        {
            DayCare daycare = DayCare.getInstance();
            Teacher t       = (Teacher)tc;
            String  group   = GroupByAge.findGroup(studentAgeInMonths);

            HashSet <Room> RoomsInCurrGroup;

            daycare.rooms.TryGetValue(group, out RoomsInCurrGroup);

            foreach (Room room in RoomsInCurrGroup)
            {
                if (room.teachers.Count < room.maxGroups)
                {
                    room.teachers.Add(t);
                    return(room);
                }
            }

            Room       newRoom = new Room();
            GroupByAge value;

            daycare.groups.TryGetValue(group, out value);
            newRoom.maxGroups = value.maxGroupsInRoom;
            newRoom.teachers.Add(t);
            RoomsInCurrGroup.Add(newRoom);

            return(newRoom);
        }
コード例 #2
0
        public static Person assignTeacher(Student student)
        {
            DayCare daycare            = DayCare.getInstance();
            int     studentAgeInMonths = ((DateTime.Now.Year - student.date_of_birth.Year) * 12) + DateTime.Now.Month - student.date_of_birth.Month;

            HashSet <Person> groupTeachers = null;
            String           group         = GroupByAge.findGroup(studentAgeInMonths);
            GroupByAge       value;

            if (daycare.groups.TryGetValue(group, out value))
            {
                groupTeachers = value.teachers;
            }

            foreach (Person teacher in groupTeachers)
            {
                Teacher t = (Teacher)teacher;
                if (t.students.Count < value.groupSize)
                {
                    t.students.Add(student);
                    return(t);
                }
            }


            HashSet <Person> availableTeachers = null;

            // if the teacher was not assigned
            if (daycare.groups.TryGetValue("availableResources", out GroupByAge res))
            {
                availableTeachers = res.teachers;
            }
            foreach (Person teacher in availableTeachers)
            {
                availableTeachers.Remove(teacher);
                groupTeachers.Add(teacher);
                Teacher t = (Teacher)teacher;
                t.students.Add(student);
                return(t);
            }

            return(null);
        }