Simeon1995

Team.cs

Feb 22nd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. public class Team
  6. {
  7. private string name;
  8. private List<Player> playersList;
  9.  
  10. public Team(string name)
  11. {
  12. this.Name = name;
  13. this.playersList = new List<Player>();
  14. }
  15.  
  16. public string Name
  17. {
  18. get { return this.name; }
  19. set
  20. {
  21. if (string.IsNullOrWhiteSpace(value))
  22. {
  23. throw new ArgumentException("A name should not be empty.");
  24. }
  25. this.name = value;
  26. }
  27. }
  28.  
  29. public int PlayersCount
  30. {
  31. get { return this.playersList.Count; }
  32. }
  33.  
  34. public void AddPlayer(Player player)
  35. {
  36. this.playersList.Add(player);
  37. }
  38.  
  39. public void RemovePlayer(string playerName)
  40. {
  41. Player player = playersList.Find(p => p.Name == playerName);
  42. if(!playersList.Contains(player))
  43. {
  44. throw new ArgumentException($"Player {playerName} is not in {this.name} team.");
  45. }
  46. else
  47. {
  48. this.playersList.Remove(player);
  49. }
  50. }
  51.  
  52. public int CalculateRate(Team team)
  53. {
  54. double rate = 0.0;
  55. foreach (var player in this.playersList)
  56. {
  57. rate += player.GetStats;
  58. }
  59. rate = rate / this.playersList.Count;
  60. rate = Math.Round(rate, 0);
  61. return (int)rate;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment