Advertisement
Adijata

RPR vježba 2, 2.

Oct 11th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8.  
  9. namespace ConsoleApplication5
  10. {
  11.  
  12.     class FudbalerU21
  13.     {
  14.         private string Ime;
  15.         private string Prezime;
  16.         private int _G_R;
  17.         private int _B_G;
  18.  
  19.         public FudbalerU21(string ime, string prezime, int gr, int bg)
  20.         {
  21.             this.Ime = ime;
  22.             this.Prezime = prezime;
  23.             this._G_R = gr;
  24.             this._B_G = bg;
  25.         }
  26.  
  27.        
  28.        
  29.         public string ime
  30.         {
  31.             set
  32.             {
  33.                 if (value == null || value == string.Empty) throw new Exception("No name provided");
  34.                 else this.Ime = value;  
  35.             }
  36.             get
  37.             {
  38.                 return this.Ime;
  39.             }
  40.         }
  41.         public int BrojGolova
  42.         { set; get; }
  43.         public int GR
  44.         { set; get; }
  45.         public string prezime
  46.         {
  47.             set
  48.             {
  49.                 if (value == null || value == string.Empty) throw new Exception("No lastname provided");
  50.                 else this.Prezime = value;
  51.             }
  52.             get
  53.             {
  54.                 return this.Prezime;
  55.             }
  56.         }
  57.         public bool DaLiJePunoljetan()
  58.         {
  59.             if (DateTime.Now.Year - GR == 21) return true; else return false;
  60.         }
  61.  
  62.        
  63.         public int godine
  64.         {
  65.             get
  66.             {
  67.                 return (DateTime.Now.Year - this._G_R);
  68.             }
  69.             set
  70.             {
  71.                 godine = DateTime.Now.Year - this._G_R;
  72.                 if (godine > 21) throw new Exception("hasjf");
  73.             }
  74.         }
  75.      
  76.  
  77.         public void Ispisi()
  78.         {
  79.             if (21 - this.godine <= 0) throw new InvalidCastException("Fudbaler je punoljetan");
  80.             Console.WriteLine(Ime + " " + Prezime + " " + _G_R + " Do punoljetnosti ostalo: {0} ", (21-this.godine));  
  81.  
  82.         }
  83.     }
  84.     class Trener
  85.     {
  86.         string Ime;
  87.         string Prezime;
  88.         int _G_R;
  89.  
  90.         public Trener(string ime, string prezime, int GR)
  91.         {
  92.             this.Ime = ime;
  93.             this.Prezime = prezime;
  94.             this._G_R = GR;
  95.         }
  96.         public string ime
  97.         {
  98.             set
  99.             {
  100.                 if (value == null || value == string.Empty) throw new Exception("No name provided");
  101.                 else this.Ime = value;
  102.             }
  103.             get
  104.             {
  105.                 return this.Ime;
  106.             }
  107.         }
  108.        
  109.         public int GR
  110.         { set; get; }
  111.         public string prezime
  112.         {
  113.             set
  114.             {
  115.                 if (value == null || value == string.Empty) throw new Exception("No lastname provided");
  116.                 else this.Prezime = value;
  117.             }
  118.             get
  119.             {
  120.                 return this.Prezime;
  121.             }
  122.         }
  123.         public int GodineIskustva
  124.         {
  125.             set
  126.             {
  127.                 value++;
  128.             }
  129.             get
  130.             {
  131.                 return GodineIskustva;
  132.             }
  133.         }
  134.  
  135.  
  136.     }
  137.  
  138.     class Klub
  139.     {
  140.        private FudbalerU21[] klub;
  141.        private string ImeKluba;
  142.        private Trener Coach;
  143.  
  144.        public FudbalerU21 club
  145.        {
  146.            get;
  147.            set;
  148.        }
  149.         public string IK
  150.         {
  151.             get; set;
  152.         }
  153.  
  154.        public Klub(FudbalerU21[] niz, string ImeK, Trener tr)
  155.        {
  156.            klub = niz;
  157.            ImeKluba = ImeK;
  158.            Coach = tr;
  159.        }
  160.        public void Ispisi()
  161.        {
  162.            foreach (FudbalerU21 i in klub)
  163.                Console.WriteLine(i.ime, i.prezime, i.BrojGolova) ;
  164.  
  165.        }
  166.         public FudbalerU21 DajNajboljeg()
  167.         {
  168.             int max = 0;
  169.             int ind=0;
  170.             for (int i = 0; i < klub.Length; i++)
  171.             {
  172.                 if (klub[i].BrojGolova > max)
  173.                 {
  174.                     max = klub[i].BrojGolova;
  175.                     ind = i;
  176.                 }
  177.  
  178.             }
  179.             return klub[ind];
  180.         }
  181.         public int DajBodove()
  182.         {
  183.             int suma=0;
  184.             for(int i=0; i<klub.Length; i++)
  185.                 suma+=klub[i].BrojGolova;
  186.             return suma;
  187.         }
  188.  
  189.  
  190.         public void EvidentirajGolove(string ime)
  191.         {
  192.             for (int i = 0; i < klub.Length; i++)
  193.             {
  194.                 if (klub[i].ime == ime)
  195.                     klub[i].BrojGolova++;
  196.             }
  197.         }
  198.  
  199.     }
  200.  
  201.     class NogometniSavez
  202.     {
  203.         private Klub[] NS;
  204.  
  205.         public void Ispisi()
  206.         {
  207.             for (int i = 0; i < NS.Length; i++)
  208.             {
  209.                 for(int j=i+1; j<NS.Length; j++)
  210.                 {
  211.                     if(NS[i].DajBodove() > NS[j].DajBodove())
  212.                     {
  213.                         Klub temp=NS[i];
  214.                         NS[i]=NS[j];
  215.                         NS[j]=temp;
  216.                     }
  217.                 }          
  218.             }
  219.             for(int i=0; i<NS.Length; i++)
  220.               Console.WriteLine( NS[i].IK);
  221.     }
  222.  
  223.     class Program
  224.     {
  225.         static void Main(string[] args)
  226.         {
  227.             try
  228.             {
  229.                 FudbalerU21 NF = new FudbalerU21("Adin", "Velić", 1993, 1000);
  230.                 NF.Ispisi();
  231.                
  232.             }
  233.             catch (InvalidCastException e )
  234.             {
  235.                 Console.WriteLine(e);
  236.  
  237.             }
  238.             Console.ReadLine();
  239.  
  240.         }
  241.     }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement