示例#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 void readFile()
        {
            string        path             = @".\teachers.csv";
            List <string> teacher_readData = new List <string>();

            if (File.Exists(path))
            {
                using (StreamReader sr = File.OpenText(path))
                {
                    string s;
                    while ((s = sr.ReadLine()) != null)
                    {
                        teacher_readData.Add(s);
                    }
                }
            }

            GroupByAge res;

            DayCare.Models.DayCare daycare = DayCare.Models.DayCare.getInstance();
            daycare.groups.TryGetValue("availableResources", out res);

            for (int i = 1; i < teacher_readData.Count; i++) // Loop through List with for
            {
                string[] line = teacher_readData[i].Split(",");
                Teacher  t    = (Teacher)Factory.Get("TEACHER");
                t.id        = Convert.ToInt32(line[0]);
                t.firstName = line[1];
                t.lastName  = line[2];
                t.age       = Convert.ToInt32(line[3]);

                DayCare.Models.DayCare.getInstance().teachers.Add(t);
                res.teachers.Add(t);
            }
        }
示例#3
0
        public static DayCare getInstance()
        {
            if (dayCare == null)
            {
                dayCare = new DayCare();
            }

            return(dayCare);
        }
示例#4
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);
        }