コード例 #1
0
        private static void AssignCoachesAndSwimmers(Coach coach1, Coach coach2, Swimmer swimmer1, Swimmer swimmer2, Swimmer swimmer3)
        {
            //coach not registered with the club
            try
            {
                swimmer1.Coach = coach1;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //Coach is not assigned to a club
            try
            {
                coach2.AddSwimmer(swimmer2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            swimmer1.Club.AddCoach(coach1);

            swimmer2.Club.AddCoach(coach2);

            //swimmer and the coach not in the same club
            try
            {
                coach2.AddSwimmer(swimmer3);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            coach1.AddSwimmer(swimmer1);
            coach1.AddSwimmer(swimmer3);

            swimmer2.Coach = coach2;

            DisplayInfo("coach 1", coach1);
            DisplayInfo("coach 2", coach2);
            DisplayInfo("club1", swimmer1.Club);
            DisplayInfo("club2", swimmer2.Club);
        }
コード例 #2
0
 public void AddSwimmer(Swimmer aSwimmer)
 {
     if (CoachIsAssignedToClub)
     {
         if (aSwimmer.Club == AssignedClubToCoach)
         {
             listOfSwimmers.Add(aSwimmer);
         }
         else
         {
             throw (new Exception("swimmer and the coach not in the same club"));
         }
     }
     else
     {
         throw (new Exception("Coach is not assigned to a club"));
     }
 }
コード例 #3
0
        private static void CreateSwimmers(out Swimmer swimmer1, out Swimmer swimmer2, out Swimmer swimmer3)
        {
            swimmer1 = new Swimmer("Bob Smith", new DateTime(1970, 1, 1),
                                   new Address("35 Elm St", "Toronto", "ON", "M2M 2M2"), 4161234567);
            DisplayInfo("swimmer1", swimmer1);

            swimmer2 = new Swimmer();
            DisplayInfo("swimmer2", swimmer2);
            swimmer2.Address     = new Address("1 King St", "Toronto", "ON", "M2M 3M3");
            swimmer2.Name        = "John Lee";
            swimmer2.PhoneNumber = 4162222222;
            swimmer2.DateOfBirth = new DateTime(1950, 12, 1);
            DisplayInfo("swimmer2", swimmer2);

            swimmer3 = new Swimmer("Ann Smith", new DateTime(1975, 1, 1),
                                   new Address("5 Queen St", "Toronto", "ON", "M2M 4M4"), 4163333333);
            DisplayInfo("swimmer3", swimmer3);
        }
コード例 #4
0
        public void EnterSwimmersTime(Registrant swimmer, string time)
        {
            int indexOfSwimmerInCollection = 0;

            SwimTimeEntered = true;
            for (int i = 0; i < NumOfRegisterant; i++)
            {
                if (CollOfRegisterants[i] == swimmer)
                {
                    indexOfSwimmerInCollection = i;
                }
            }
            if (AlreadyEntered(swimmer, CollOfRegisterants) == true)
            {
                aSwimmer = (Swimmer)swimmer;
                CollOfSwims[indexOfSwimmerInCollection].TimeSwam = time;
                time = "0:" + time;
                aSwimmer.AddAsBestTime(PoolTypeOfEvent, Stroke, Distance, TimeSpan.Parse(time));
            }
            else
            {
                throw (new Exception("Swimmer has not entered the event"));
            }
        }