Example #1
0
        public ErrorCode ParseText(string[] _inputText)
        {
            uint line = 0;

            while (++line <= _inputText.Length)
            {
                if (_inputText[line] != "Open")
                {
                    continue;
                }

                CourseSection newCourse = new CourseSection();

                //read course name
                line++;
                try
                {
                    ReadCourseName(_inputText[line], newCourse);
                }
                catch (InvalidCourseNameException e)
                {
                    return(new ErrorCode(e.Message, line));
                }
            }

            return(new ErrorCode());
        }
Example #2
0
 private void ReadCourseName(string line, ref CourseSection course)
 {
     string[] nameSubstrings = line.Split(new char[] { ' ' }, 3);
     string[] codeSubstrings = nameSubstrings[0].Split(new char[] { '*' });
     course.SetCode(codeSubstrings[0] + "*" + codeSubstrings[1]);
     course.SetSection(codeSubstrings[2]);
     course.SetName(nameSubstrings[2]);
 }
Example #3
0
        public bool HasConflict(CourseSection _other)
        {
            //check everyone of this course's timeslots against everyone of other's timeslots
            foreach (TimeSlot timeSlot1 in this.timeSlots)
            {
                foreach (TimeSlot timeSlot2 in _other.timeSlots)
                {
                    if (timeSlot1.HasConflict(timeSlot2))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #4
0
        private void ReadCourseName(string _line, CourseSection _courseSection)
        {
            try
            {
                string[] nameSubstrings = _line.Split(new char[] { ' ' }, 3);
                string[] codeSubstrings = nameSubstrings[0].Split(new char[] { '*' });

                _courseSection.SetName(codeSubstrings[0] + "*" + codeSubstrings[1]);
                _courseSection.SetSection(codeSubstrings[2]);
                _courseSection.SetName(nameSubstrings[2]);
            }
            catch (System.IndexOutOfRangeException e)
            {
                throw new InvalidCourseNameException("Course name is not in the expected format.");
            }
        }
Example #5
0
        public void LoadCourses(string[] inputText)
        {
            coursesList.Clear();

            int line = 1;

            while (line < inputText.Length)
            {
                if (inputText[line++] != "Open")
                {
                    continue;
                }

                CourseSection newCourse = new CourseSection();

                //get course name
                ReadCourseName(inputText[line], ref newCourse);

                line += 2;
                //read the timeslots
                List <TimeSlot> timeSlots = new List <TimeSlot>();
                do
                {
                    string classType = inputText[line].Substring(0, 3);
                    if (classType == "LEC" || classType == "LAB")
                    {
                        List <TimeSlot.Day> days = ReadDays(inputText[line++]);
                        Time[] times             = ReadTimes(inputText[line++]);
                        string location          = inputText[line++];

                        foreach (TimeSlot.Day day in days)
                        {
                            timeSlots.Add(new TimeSlot(times[0], times[1], day, classType, location));
                        }
                    }
                    else
                    {
                        break;
                    }
                } while (true);
                newCourse.SetTimeSlots(timeSlots);

                //read instructor
                newCourse.SetInstructor(inputText[line]);

                bool foundCourse = false;
                //check if course list already exist in list
                foreach (List <CourseSection> list in coursesList)
                {
                    //if course list exists, add to the list
                    if (list[0].GetName() == newCourse.GetName())
                    {
                        list.Add(newCourse);
                        foundCourse = true;
                    }
                }

                //course list doesn't exist, created new list and add course to list
                if (!foundCourse)
                {
                    coursesList.Add(new List <CourseSection> {
                        newCourse
                    });
                }
            }

            //sort list by the number of sections per course
            coursesList = coursesList.OrderBy(o => o.Count).ToList();
        }
Example #6
0
 public bool IsSameCourse(CourseSection _other) => (this.name == _other.name && this.code == _other.code);