Example #1
0
        static void Main(string[] args)
        {
            string      command = Console.ReadLine();
            List <Team> teams   = new List <Team>();

            while (command != "END")
            {
                string[] arr = command.Split(";", StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    string teamName = arr[1];
                    switch (arr[0])
                    {
                    case "Team":
                        Team team = new Team(teamName);
                        teams.Add(team);
                        break;

                    case "Add":
                        string playerName = arr[2];
                        double endurance  = double.Parse(arr[3]);
                        double sprint     = double.Parse(arr[4]);
                        double dribble    = double.Parse(arr[5]);
                        double passing    = double.Parse(arr[6]);
                        double shooting   = double.Parse(arr[7]);

                        if (!teams.Any(x => x.Name == teamName))
                        {
                            throw new ArgumentException($"Team {teamName} does not exist.");
                        }
                        team = teams.FirstOrDefault(x => x.Name == teamName);
                        Player player = new Player(playerName, new Stats(endurance, sprint, dribble, passing, shooting));
                        team.AddPlayer(player);
                        break;

                    case "Remove":
                        playerName = arr[2];

                        if (!teams.Any(x => x.Name == teamName))
                        {
                            throw new ArgumentException($"Team {teamName} does not exist.");
                        }
                        team = teams.FirstOrDefault(x => x.Name == teamName);
                        team.Remove(playerName);
                        break;

                    case "Rating":
                        if (!teams.Any(x => x.Name == teamName))
                        {
                            throw new ArgumentException($"Team {teamName} does not exist.");
                        }
                        team = teams.FirstOrDefault(x => x.Name == teamName);
                        team.GetRatings(teamName);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                command = Console.ReadLine();
            }
        }
        public void Run()
        {
            string      input = string.Empty;
            List <Team> teams = new List <Team>();

            while ((input = Console.ReadLine()) != "END")
            {
                try
                {
                    var    data     = input.Split(";");
                    string teamName = data[1];
                    if (data[0] == "Team")
                    {
                        Team team = new Team(teamName);
                        teams.Add(team);
                    }
                    if (data[0] == "Add")
                    {
                        var playerName = data[2];
                        if (!teams.Any(x => x.TeamName == teamName))
                        {
                            throw new ArgumentException(String.Format(Validator.TeamNotExist, teamName));
                        }
                        string[] stats = new string[]
                        {
                            data[3],
                            data[4],
                            data[5],
                            data[6],
                            data[7]
                        };
                        Stats  statsOfPlayer = new Stats(stats);
                        Player player        = new Player(playerName, statsOfPlayer);
                        Team   team          = teams.FirstOrDefault(x => x.TeamName == teamName);
                        team.Add(player);
                    }
                    if (data[0] == "Remove")
                    {
                        Team team       = teams.FirstOrDefault(x => x.TeamName == teamName);
                        var  playerName = data[2];
                        team.Remove(playerName);
                    }
                    if (data[0] == "Rating")
                    {
                        if (!teams.Any(x => x.TeamName == teamName))
                        {
                            throw new ArgumentException(String.Format(Validator.TeamNotExist, teamName));
                        }
                        foreach (var team in teams)
                        {
                            if (team.TeamName == teamName)
                            {
                                Console.WriteLine(team);
                            }
                        }
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Example #3
0
        public void Run()
        {
            Teams teams = new Teams();

            while (true)
            {
                try
                {
                    string input = Console.ReadLine();

                    if (input == "END")
                    {
                        break;
                    }

                    string[] args = input
                                    .Split(";");

                    string command  = args[0];
                    string teamName = args[1];

                    if (command == "Team")
                    {
                        Team team = new Team(teamName);
                        teams.AddTeam(team);
                    }
                    else if (command == "Add")
                    {
                        teams.ValidTeam(teamName);

                        string playerName = args[2];
                        int    endurance  = int.Parse(args[3]);
                        int    sprint     = int.Parse(args[4]);
                        int    dribble    = int.Parse(args[5]);
                        int    passing    = int.Parse(args[6]);
                        int    shooting   = int.Parse(args[7]);

                        Player player = new Player(playerName, endurance, sprint, dribble, passing, shooting);

                        Team currentTeam = teams.TeamsCollection.FirstOrDefault(x => x.Name == teamName);

                        currentTeam.Add(player);
                    }
                    else if (command == "Remove")
                    {
                        teams.ValidTeam(teamName);

                        string playerName = args[2];

                        Team currentTeam = teams.TeamsCollection.FirstOrDefault(x => x.Name == teamName);

                        currentTeam.Remove(playerName);
                    }
                    else if (command == "Rating")
                    {
                        teams.ValidTeam(teamName);

                        Team currentTeam = teams.TeamsCollection.FirstOrDefault(x => x.Name == teamName);

                        Console.WriteLine(currentTeam);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }