public void AddClass(ClassOfStudents aClass) { if (this.classes.Count > 0) { foreach (var cls in this.classes) { if (cls.Equals(aClass)) { throw new ArgumentException("Already added!"); } } this.classes.Add(aClass); } }
public bool RemoveClass(ClassOfStudents aClass) { if (this.classes.Count > 0) { foreach (var cls in this.classes) { if (cls.Equals(aClass)) { this.classes.Remove(cls); return(true); } } } return(false); }
private static void TestSchool() { var math = new School.Discipline("Math"); Console.WriteLine("math.ToString(): " + math); var petrov = new School.Teacher("Petrov"); Console.WriteLine("Petrov.ToString(): " + petrov); petrov.AddDiscipline(math); // petrov.AddDiscipline(math); <-exeption petrov.RemoveDiscipline(math); petrov.AddDiscipline(math); var pesho = new School.Student("Pesho"); Console.WriteLine("Pesho.ToString(): " + pesho); var gosho = new School.Student("Gosho"); pesho.Comment = "Pesho hates math for no reason!"; Console.WriteLine("Pesho.Comment: " + pesho.Comment); var fiveB = new School.ClassOfStudents("FiveB"); Console.WriteLine("FiveB.ToString(): " + fiveB.ToString()); fiveB.AddStudent(pesho); fiveB.RemoveStudent(pesho); fiveB.AddStudent(pesho); fiveB.AddStudent(gosho); fiveB.AddTeacher(petrov); var sch = new School.School("2865th"); Console.WriteLine("Sch.ToString(): " + sch); sch.AddClass(fiveB); sch.Comment = "The school"; Console.WriteLine("Sch.Comment: " + sch.Comment); }