public CreateBoxerCommand(IList <string> commandLine) : base(commandLine)
        {
            if (commandLine.Count < 6)
            {
                throw new ArgumentException(GlobalConstants.ParametersCountInvalid);
            }

            int wins   = 0;
            int losses = 0;

            if (int.TryParse(commandLine[4], out wins) && int.TryParse(commandLine[5], out losses))
            {
                this.boxer = base.Factory.CreateBoxer(commandLine[0],
                                                      commandLine[1],
                                                      commandLine[2],
                                                      commandLine[3],
                                                      wins,
                                                      losses);
                base.Committee.Olympians.Add(this.boxer);
            }
            else
            {
                throw new ArgumentException(GlobalConstants.WinsLossesMustBeNumbers);
            }
        }
Exemplo n.º 2
0
        public override string Execute()
        {
            var parameters = this.CommandParameters;


            string firstName = parameters[0];
            string lastName  = parameters[1];
            string country   = parameters[2];
            string category  = parameters[3];

            //int wins = int.Parse(parameters[4]);
            //int losses = int.Parse(parameters[5]);

            int  wins;
            bool parsedWin = int.TryParse(parameters[4], out wins);

            int  losses;
            bool parsedLosses = int.TryParse(parameters[5], out losses);

            if (!parsedWin || !parsedLosses)
            {
                throw new ArgumentException(GlobalConstants.WinsLossesMustBeNumbers);
            }

            IOlympian boxer = this.Factory.CreateBoxer(firstName, lastName, country, category, wins, losses);

            this.Committee.Olympians.Add(boxer);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Created Boxer");
            sb.AppendLine(boxer.ToString());

            return(sb.ToString().TrimEnd());
        }
Exemplo n.º 3
0
        public override string Execute()
        {
            var parameters = this.CommandParameters;

            if (parameters.Count < Constants.SprinterMinParamsCount)
            {
                throw new ArgumentException(GlobalConstants.ParametersCountInvalid);
            }

            string firstName = parameters[0];
            string lastName  = parameters[1];
            string country   = parameters[2];

            // ["100/19.5", "200/25.3"]
            var recordsAsArr = parameters.Skip(Constants.SprinterMinParamsCount).ToArray();

            foreach (string record in recordsAsArr)
            {
                var    splitted = record.Split('/');
                string track    = splitted[0];
                double time     = double.Parse(splitted[1]);
                this.records[track] = time;
            }

            IOlympian sprinter = this.Factory.CreateSprinter(firstName, lastName, country, this.records);

            this.Committee.Olympians.Add(sprinter);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(Constants.CreatedSprinterText);
            sb.AppendLine(sprinter.ToString());

            return(sb.ToString().TrimEnd());
        }
        public override string Execute()
        {
            var parameters = this.CommandParameters;

            string firstName = parameters[0];
            string lastName  = parameters[1];
            string country   = parameters[2];

            // ["100/19.5", "200/25.3"]

            var recordsToArray = parameters.Skip(3).ToArray();

            foreach (var rec in recordsToArray)
            {
                var    splitted   = rec.Split('/');
                string discipline = splitted[0];
                double time       = double.Parse(splitted[1]);
                this.records[discipline] = time;
            }

            IOlympian sprinter = this.Factory.CreateSprinter(firstName, lastName, country, records);

            this.Committee.Olympians.Add(sprinter);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Created Sprinter");
            sb.AppendLine(sprinter.ToString());

            return(sb.ToString().TrimEnd());
        }
 public CreateBoxerCommand(IList <string> commandLine) : base(commandLine)
 {
     if (commandLine.Count < 3)
     {
         throw new ArgumentException(GlobalConstants.ParametersCountInvalid);
     }
     this.currentBoxer = Factory.CreateBoxer(commandLine[0], commandLine[1], commandLine[2], commandLine[3], Int32.Parse(commandLine[4]), Int32.Parse(commandLine[5]));
     this.Committee.Olympians.Add(this.currentBoxer);
 }
        public override string Execute()
        {
            IOlympian olympian = OlympicsFactory.Instance.CreateSprinter(this.CommandParameters[0], this.CommandParameters[1],
                                                                         this.CommandParameters[2], this.records);

            this.Committee.Olympians.Add(olympian);
            return(string.Format(@"Created {0}
{1}", nameof(Sprinter), olympian.ToString()));
        }
        public CreateSprinterCommand(IList <string> commandLine) : base(commandLine)
        {
            if (commandLine.Count < 3)
            {
                throw new ArgumentException(GlobalConstants.ParametersCountInvalid);
            }
            commandLine.ValidateIfNull();
            records  = new Dictionary <string, double>();
            records  = commandLine.Skip(3).Select(x => x.Split('/')).ToDictionary(x => x.First(), x => double.Parse(x.Last(), CultureInfo.InvariantCulture));
            sprinter = base.Factory.CreateSprinter(commandLine[0], commandLine[1], commandLine[2], records);

            base.Committee.Olympians.Add(this.sprinter);
        }
        public override string Execute()
        {
            int winsParsed;
            int lossesParsed;

            if (!int.TryParse(this.CommandParameters[4], out winsParsed) || !int.TryParse(this.CommandParameters[5], out lossesParsed))
            {
                throw new ArgumentException(GlobalConstants.WinsLossesMustBeNumbers);
            }

            IOlympian olympian = OlympicsFactory.Instance.CreateBoxer(this.CommandParameters[0], this.CommandParameters[1],
                                                                      this.CommandParameters[2], this.CommandParameters[3], winsParsed, lossesParsed);

            this.Committee.Olympians.Add(olympian);
            return(string.Format(@"Created {0}
{1}", nameof(Boxer), olympian.ToString()));
        }
        public CreateSprinterCommand(IList <string> commandLine) : base(commandLine)
        {
            this.records = new Dictionary <string, double>();
            int recordsCounter = 3;

            while (commandLine.Count > recordsCounter)
            {
                string[] tempRecords = commandLine[recordsCounter].Split('/');
                this.records.Add(tempRecords[0], Double.Parse(tempRecords[1]));
                recordsCounter++;
            }
            if (commandLine.Count < 3)
            {
                throw new ArgumentException(GlobalConstants.ParametersCountInvalid);
            }
            this.currentSprinter = Factory.CreateSprinter(commandLine[0], commandLine[1], commandLine[2], this.records);
            this.Committee.Olympians.Add(this.currentSprinter);
        }
        public override string Execute()
        {
            if (CommandParameters.Count < this.AmountOfInfo())
            {
                throw new Exception(GlobalConstants.ParametersCountInvalid);
            }
            string firstName   = this.CommandParameters[0];
            string lastName    = this.CommandParameters[1];
            string nationality = this.CommandParameters[2];

            IOlympian olympian       = this.Olimpian(firstName, lastName, nationality);
            string    returnOlympian = String.Format(@"Created {0}
{1}",
                                                     this.OlympianType(),
                                                     olympian.ToString()
                                                     );

            this.Committee.Olympians.Add(olympian);
            return(returnOlympian);
        }
Exemplo n.º 11
0
 public override string Execute()
 {
     this.olympian = this.CreateOlympian();
     this.Committee.Olympians.Add(this.olympian);
     return(string.Format($"Created {this.olympian.GetType().Name}\n{this.olympian}"));
 }