public void PrintMessages(RegisterTeam currentRegisterTeam, List <RegisterTeam> registerTeams) { bool isValid = true; foreach (var registerTeam in registerTeams) { if (registerTeam.TeamName == currentRegisterTeam.TeamName) { isValid = false; // If user tries to create a team more than once a message should be displayed: Console.WriteLine($"Team {TeamName} was already created!"); } if (registerTeam.UserCreator == currentRegisterTeam.UserCreator) { isValid = false; // Creator of a team cannot create another team - message should be thrown: Console.WriteLine($"{UserCreator} cannot create another team!"); } } // if everything is OK if (isValid) { Console.WriteLine($"Team {TeamName} has been created by {UserCreator}!"); registerTeams.Add(currentRegisterTeam); } }
static void Main(string[] args) { int countOfTeams = int.Parse(Console.ReadLine()); List <RegisterTeam> registerTeams = new List <RegisterTeam>(); for (int i = 0; i < countOfTeams; i++) { string[] registedTeamInfo = Console.ReadLine().Split('-'); string userCreator = registedTeamInfo[0]; string teamName = registedTeamInfo[1]; RegisterTeam currentRegisterTeam = new RegisterTeam(userCreator, teamName); currentRegisterTeam.PrintMessages(currentRegisterTeam, registerTeams); } List <Join> joins = new List <Join>(); while (true) { string[] joinInfo = Console.ReadLine().Split("->"); if (joinInfo[0] == "end of assignment") { break; } string userToJoin = joinInfo[0]; string teamJoin = joinInfo[1]; Join currentJoin = new Join(userToJoin, teamJoin); currentJoin.PrintMessages(currentJoin, registerTeams, joins); } PrintResult(registerTeams, joins); }