public void AddSwimmer(Swimmer swimmer) { if (!Swimmers.Contains(swimmer)) { if (swimmer.Club == null) { throw new Exception($"swimmer {swimmer.Name} not assigned club"); } else if (Club == null) { throw new Exception($"Coach {Name} not assigned club"); } else if (swimmer.Club != Club) { throw new Exception($"Coach {Name} and swimmer {swimmer.Name} are not in the same club"); } else if (swimmer.Club == Club) { if (swimmer.Coach == null) { swimmer.Coach = this; } else { Swimmers.Add(swimmer); } } } }
public void AddSwimmer(Swimmer swimmer) { //if (Swimmers.Count< Max_Registrants) if (numberOfRegistrants < Max_Registrants) { //if (Swimmers[Swimmers.Count].RegistrationNumber != swimmer.RegistrationNumber) //{ // //Swimmers[numberOfRegistrants++] = swimmer; // Swimmers.Add(swimmer); // swimmer.Coach = this; //} if (!Swimmers.Contains(swimmer)) { Swimmers[numberOfRegistrants++] = swimmer; //Swimmers.Add(swimmer); //if(swimmer.Club.ClubNumber==swimmer.Coach.Club.ClubNumber) swimmer.Coach = this; //else // Console.WriteLine("Club number is not same"); } else { //throw new Exception("Swimmer already assigned to " + Swimmers[numberOfRegistrants++].Coach.Name); } } else { throw new Exception("Cannot register more than 20"); } }
public void Add(Registrant swimmer) { if (!Swimmers.Contains(swimmer)) { Swimmers.Add(swimmer); } else { throw new Exception("The swimmer already added into swimmer manager"); } }
/*Add Swimemr Method*/ public void AddSwimmer(Swimmer newSwimmer) { if (Club == newSwimmer.Club && !Swimmers.Contains(newSwimmer)) { if (newSwimmer.Coach != this) { newSwimmer.Coach = this; } if (!Swimmers.Contains(newSwimmer)) { Swimmers.Add(newSwimmer); } } else if (Club != newSwimmer.Club && Club != null) { throw new Exception("Coach and swimmer are in different club"); } else if (Club == null) { throw new Exception("Coach is unassigned"); } }
public void Load(string fileName, string delimiter) { int regNo; DateTime date; long phone; TextReader reader = new StreamReader(fileName); string line = reader.ReadLine(); string[] fields; while (line != null) { try { fields = line.Split(Convert.ToChar(delimiter)); for (int i = 0; i < number; i++) { if (fields[1] == "") { throw new Exception("Invalid swimmer record. Invalid swimmer name: \n\t" + line); } else if (!DateTime.TryParse(fields[2], out date)) { throw new Exception("Invalid swimmer record. Birth date is inalid: \n\t" + line); } else if (!long.TryParse(fields[7], out phone)) { throw new Exception("Invalid swimmer record. Phone number wrong format: \n\t" + line); } else if (!int.TryParse(fields[0], out regNo)) { throw new Exception("Invalid swimmer record. Invalid registration number: \n\t" + line); } else if (GetByRegNum(Convert.ToInt32(fields[0])) != null) { if (Swimmers.Contains(GetByRegNum(Convert.ToInt32(fields[0])))) { throw new Exception("Invalid swimmer record. Swimmer with the registration number already exists: \n\t" + line); } else { Address address = new Address(fields[3], fields[4], fields[5], fields[6]); Registrant newSwimmer = new Registrant(Convert.ToInt32(fields[0]), fields[1], Convert.ToDateTime(fields[2]), address, Convert.ToUInt32(fields[7])); Add(newSwimmer); } } } Address address1 = new Address(fields[3], fields[4], fields[5], fields[6]); Registrant newSwimmer1 = new Registrant(Convert.ToInt32(fields[0]), fields[1], Convert.ToDateTime(fields[2]), address1, Convert.ToUInt32(fields[7])); Add(newSwimmer1); } catch (Exception e) { Console.WriteLine(e.Message); } finally { if (Swimmers[number] != null) { ++number; reader.Close(); } } line = reader.ReadLine(); } }