Exemplo n.º 1
0
        public string AddAthlete(string gymName, string athleteType, string athleteName, string motivation, int numberOfMedals)
        {
            var gym = this.gyms.FirstOrDefault(g => g.Name == gymName);

            string result = string.Empty;

            if (athleteType == "Boxer" && gym.Name == gymName && gym.GetType().Name == "BoxingGym")
            {
                IAthlete athlete = new Boxer(athleteName, motivation, numberOfMedals);
                gym.AddAthlete(athlete);
                result = $"Successfully added {athleteType} to {gymName}.";
            }
            else if (athleteType == "Weightlifter" && gym.Name == gymName && gym.GetType().Name == "WeightliftingGym")
            {
                IAthlete athlete = new Weightlifter(athleteName, motivation, numberOfMedals);
                gym.AddAthlete(athlete);
                result = $"Successfully added {athleteType} to {gymName}.";
            }
            else if (string.IsNullOrWhiteSpace(athleteType) || athleteType != "Weightlifter" || athleteType != "Boxer")
            {
                throw new InvalidOperationException("Invalid athlete type");
            }
            else
            {
                result = "The gym is not appropriate.";
            }
            return(result);
        }
Exemplo n.º 2
0
        public string AddAthlete(string gymName, string athleteType, string athleteName, string motivation, int numberOfMedals)
        {
            IAthlete athlete;
            IGym     gym = this.gyms.First(x => x.Name == gymName);

            if (athleteType == nameof(Boxer))
            {
                athlete = new Boxer(athleteName, motivation, numberOfMedals);
            }
            else if (athleteType == nameof(Weightlifter))
            {
                athlete = new Weightlifter(athleteName, motivation, numberOfMedals);
            }
            else
            {
                throw new InvalidOperationException(InvalidAthleteType);
            }

            var notAppropriateForBoxer =
                !(gym.GetType().Name == nameof(BoxingGym) && athleteType == nameof(Boxer));

            var notAppropriateForWeightlifter =
                !(gym.GetType().Name == nameof(WeightliftingGym) && athleteType == nameof(Weightlifter));

            if (notAppropriateForBoxer && notAppropriateForWeightlifter)
            {
                return(InappropriateGym);
            }

            gym.AddAthlete(athlete);
            return(string.Format(EntityAddedToGym, athleteType, gymName));
        }
Exemplo n.º 3
0
        public string AddAthlete(string gymName, string athleteType, string athleteName, string motivation, int numberOfMedals)
        {
            IAthlete athlete;

            switch (athleteType)
            {
            case nameof(Boxer):
                athlete = new Boxer(athleteName, motivation, numberOfMedals);
                break;

            case nameof(Weightlifter):
                athlete = new Weightlifter(athleteName, motivation, numberOfMedals);
                break;

            default:
                throw new InvalidOperationException(ExceptionMessages.InvalidAthleteType);
            }

            IGym gym = this.gyms.First(g => g.Name == gymName);

            if (athlete.GetType().Name == nameof(Boxer) && gym.GetType().Name == nameof(BoxingGym))
            {
                gym.AddAthlete(athlete);
            }
            else if (athlete.GetType().Name == nameof(Weightlifter) && gym.GetType().Name == nameof(WeightliftingGym))
            {
                gym.AddAthlete(athlete);
            }
            else
            {
                return(OutputMessages.InappropriateGym);
            }

            return(string.Format(OutputMessages.EntityAddedToGym, athleteType, gymName));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Sort:");
            Footballer[] arr = new Footballer[5];
            for (int i = 0; i < 5; i++)
            {
                arr[i]             = new Footballer();
                arr[i].ScoredGoals = 7 - i;
            }
            foreach (var footballer in arr)
            {
                Console.WriteLine(footballer.ScoredGoals);
            }
            Array.Sort(arr);
            Console.WriteLine();
            foreach (var footballer in arr)
            {
                Console.WriteLine(footballer.ScoredGoals);
            }
            Console.WriteLine("\nInterchangeability:");
            Footballer igor = new Footballer();

            igor.Equipment = new LowLevelEquipment();
            igor.Equipment.Clothes();
            igor.Equipment = new MedLevelEquipment();
            igor.Equipment.Clothes();
            igor.Equipment = new HighLevelEquipment();
            igor.Equipment.Clothes();
            Console.WriteLine("\nComparison:");
            Weightlifter tolya = new Weightlifter();

            tolya.Weight = 95;
            Weightlifter kostya = new Weightlifter();

            kostya.Weight = 90;
            Console.WriteLine(tolya.CompareTo(kostya));
            Console.WriteLine("\nCommon feature:");
            var participants = new List <ICompetable>
            {
                new Footballer(),
                new Athlete(),
                new Weightlifter()
            };

            foreach (var participant in participants)
            {
                Competition(participant);
                Console.WriteLine();
            }
            Console.ReadKey();
        }