//constructor public classItem(CourseTime CourseTimes, Teacher Teacher, List<Student> EnrolledStudents, Classroom Room, Cours Course) { courseTimes = CourseTimes; teacher = Teacher; enrolledStudents = EnrolledStudents; room = Room; course = Course; }
//======================================method to add teacher========================================== public static void AddTeacher() { string name; string phone; string email; Courses approvedCourses = new Courses(); long check; Console.Write("Enter Name\n"); name = Console.ReadLine(); Console.Write("Enter 10 digit Phone number\n"); string input = Console.ReadLine(); try { check = Convert.ToInt64(input); } catch { Console.WriteLine("Phone number must be 10 numerical digits"); return; } if (input.ToString().Length != 10) { Console.WriteLine("Phone number entered is not 10 digits, please try again"); return; } else { phone = input; } Console.Write("Enter Email address\n"); email = Console.ReadLine(); //display all course options if (name == "" || email == "") { Console.WriteLine("One or more fields left empty, please try again"); return; } foreach (Cours c in dm.DBCourses) { Console.WriteLine("Course ID: {0}\tName: {1}", c.CourseID, c.CourseName); } //bool and while loop to keep adding courses until the user stops bool keepAdding = true; //loops through all courses comparing entered ID to courseIDs. If a match is found, bool is set to true and if statement is entered, assigning match //to the list. After this is completed, ask user if they want to add more classes and loop again. while (keepAdding) { Console.WriteLine("Enter ID of a course this teacher can teach"); //setting up tryparse for error checking string answer = Console.ReadLine(); int id; bool result = int.TryParse(answer, out id); bool match = false; Cours matchedCourse = null; foreach (Cours c in dm.DBCourses) { if (id == c.CourseID) { match = true; matchedCourse = c; } } if (match == true) { //nested if statement checks for duplicates and writes and error message if found. if (approvedCourses.Contains(matchedCourse)) { Console.WriteLine("this course has already been added, you can't add it twice!"); } else { approvedCourses.Add(matchedCourse); Console.WriteLine("class successfully added"); } } else { Console.WriteLine("invalid class number entered"); return; } Console.WriteLine("Can this teacher teach another course?\n1...Yes\n2...No"); string anotherClass = Console.ReadLine(); switch (anotherClass) { case "1": break; case "2": keepAdding = false; break; } } //once all classes are assigned, check for null, then create teacher with those classes //and add him/her to list if (approvedCourses.CourseCollection.Count != 0) { //create empty list of classes to be used when scheduling a class List<classItem> classesWith = new List<classItem>(); //set bool value to true on all teachers bool isTeacher = true; Teacher t = new Teacher(name, phone, email, isTeacher, classesWith, approvedCourses); if (people.Contains(t)) { Console.WriteLine("The name, phone number, or email entered is already taken, please enter a new one"); return; } else { people.Add(t); //bool used in scheduling a class for error checking hasTeacher = true; Console.WriteLine("{0} added Successfully!", t.Name); } } else { Console.WriteLine("No courses were successfully added that this teacher can teach. Teacher was not added."); } }
//displays teacher-specific information public static void displayTeacherInfo(Teacher t) { if (t.CoursesWith.Count == 0) { Console.WriteLine("Teacher is not scheduled to teach any classes"); } else { Console.WriteLine("List of courses this teacher is approved to teach:"); foreach (Cours c in t.ApprovedCourses) { Console.WriteLine("\t{0}", c.CourseName); } Console.WriteLine("Information regarding courses this teacher is teaching:"); foreach (classItem ci in t.CoursesWith) { Console.WriteLine("\tCourse name: {0}\n\tClassroom number: {1}\n\tCourse time: {2}\n\tNumber of students registered: {3}", ci.Course.CourseName, ci.Room.RoomNumber, ci.CourseTimes.TimeFrame, ci.EnrolledStudents.Count); } } }