desislava_topuzakova

Coach.cs

May 10th, 2020
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Exam_Preparation_2_Fitness
  7. {
  8.     public class Coach
  9.     {
  10.         //име, опит, списък от клиенти, пари
  11.         private string name;
  12.         private int experience;
  13.         private List<Athlete> clients;
  14.         private double money;
  15.         public Coach(string name, int experience)
  16.         {
  17.             Name = name;
  18.             Experience = experience;
  19.             Money = 0;
  20.             Clients = new List<Athlete>();
  21.         }
  22.  
  23.         public Coach(string name, int experience, double money)
  24.         {
  25.             Name = name;
  26.             Experience = experience;
  27.             Money = money;
  28.             Clients = new List<Athlete>();
  29.         }
  30.  
  31.  
  32.  
  33.         public string Name
  34.         {
  35.             get
  36.             {
  37.                 return name;
  38.             }
  39.             set
  40.             {
  41.                 if (value.Length <= 2)
  42.                 {
  43.                     throw new ArgumentException("Invalid coach name!");
  44.                 }
  45.                 name = value;
  46.             }
  47.         }
  48.  
  49.         public int Experience
  50.         {
  51.             get
  52.             {
  53.                 return experience;
  54.             }
  55.             set
  56.             {
  57.                 experience = value;
  58.             }
  59.         }
  60.  
  61.         public List<Athlete> Clients
  62.         {
  63.             get
  64.             {
  65.                 return clients;
  66.             }
  67.             set
  68.             {
  69.                 clients = value;
  70.             }
  71.         }
  72.  
  73.         public double Money
  74.         {
  75.             get
  76.             {
  77.                 return money;
  78.             }
  79.             set
  80.             {
  81.                 money = value;
  82.             }
  83.         }
  84.  
  85.         public override string ToString()
  86.         {
  87.             //Coach: <име> has experience <опит> and his current money balace is: <пари>
  88.             return $"Coach: {name} has experience {experience} and his current money balace is: {money:F2}";
  89.         }
  90.  
  91.         public void AddNewClient(Athlete a)
  92.         {
  93.             clients.Add(a);
  94.         }
  95.  
  96.         public bool LooseClient(string name)
  97.         {
  98.             foreach (Athlete client in clients)
  99.             {
  100.                 if (client.Name == name)
  101.                 {
  102.                     return clients.Remove(client);
  103.                 }
  104.             }
  105.             return false;
  106.         }
  107.  
  108.         public int GetClientsCount()
  109.         {
  110.             return clients.Count;
  111.         }
  112.  
  113.         public List<Athlete> GetAllClientsTougherThan(double strength)
  114.         {
  115.             //ВСИЧКИ КЛИЕНТИ СЪС СИЛА > ОТ strength
  116.             List<Athlete> stronger = new List<Athlete>();
  117.             foreach (Athlete client in clients)
  118.             {
  119.                 if (client.Strenght > strength)
  120.                 {
  121.                     stronger.Add(client);
  122.                 }
  123.             }
  124.             return stronger;
  125.         }
  126.         public void SpendMoneyOnSupplements(double amount)
  127.         {
  128.             if (amount > money)
  129.             {
  130.                 throw new ArgumentException("Insufficient balance");
  131.             }
  132.             money -= amount;
  133.         }
  134.  
  135.         public void TrainHard()
  136.         {
  137.             experience += 5;
  138.         }
  139.  
  140.         public void TrainClient(Athlete athlete)
  141.         {
  142.             athlete.Strenght += 5;
  143.             experience += 1;
  144.             money += athlete.Strenght * 0.75;
  145.         }
  146.  
  147.         public int RemoveAllClientsLeakerThan(int strength)
  148.         {
  149.             return clients.RemoveAll(a => a.Strenght < strength);
  150.         }
  151.  
  152.         public Athlete GetToughestClient()
  153.         {
  154.             return clients.OrderByDescending(client => client.Strenght).First();
  155.         }
  156.  
  157.  
  158.     }
  159. }
Add Comment
Please, Sign In to add comment