static void Main(string[] args) { List <Team> teams = new List <Team>(); while (true) { string[] token = Console.ReadLine().Split(";"); if (token[0] == "END") { break; } try { if (token[0] == "Team") { teams.Add(new Team(token[1])); } else if (token[0] == "Add") { if (!teams.Any(x => x.Name == token[1])) { throw new Exception($"Team {token[1]} does not exist."); } else { Team currentTeam = teams.FirstOrDefault(x => x.Name == token[1]); currentTeam.Add(new Player(token[2], int.Parse(token[3]), int.Parse(token[4]), int.Parse(token[5]), int.Parse(token[6]), int.Parse(token[7]))); } } else if (token[0] == "Remove") { var team2 = teams.First(x => x.Name == token[1]); team2.Remove(token[2]); } else if (token[0] == "Rating") { if (!teams.Any(x => x.Name == token[1])) { throw new Exception($"Team {token[1]} does not exist."); } else { Team currentTeam = teams.First(x => x.Name == token[1]); Console.WriteLine($"{currentTeam.Name} - {currentTeam.Rating}"); } } } catch (Exception e) { Console.WriteLine(e.Message); } } }
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); } } }
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); } } }